[R] frequency table?
Jim Lemon
jim at bitwrit.com.au
Mon Dec 5 09:23:13 CET 2011
On 12/04/2011 08:21 PM, set wrote:
> Hello R-users,
>
> I've got a file with individuals as colums and the clusters where they occur
> in as rows. And I wanted a table which tells me how many times each
> individual occurs with another. I don't really know how such a table is
> called...it is not a frequency table....My eventual goal is to make
> Venn-diagrams from the occurence of my individuals.
>
> So I've this:
>
> cluster ind1 ind2 ind3 etc.
> 1 0 1 2
> 2 3 0 1
> 3 1 1 1
>
> And I want to go to this:
> ind1 ind2 ind3
> ind1 0 4 2
> ind2 4 0 4
> ind3 2 4 1
>
> is there a way to do this?
Hi set,
Your example is a bit hard to figure out. In particular, individual 1
seems to be in cluster 2 three times, and individual 3 in cluster 1
twice. I could understand it if the top table looked like this:
cluster ind1 ind2 ind3 ...
1 0 1 1 ...
2 1 0 1 ...
3 1 1 1 ...
That tells me that individual 1 is in cluster 2 and 3 but not in cluster
1, and so on. If you look at the first example in the intersectDiagram
function in the plotrix package, you will see something similar, except
that individuals are rows and common attributes (belonging to sets) are
columns. You can get an intersection diagram from that showing how many
individuals are in each combination of sets. This is similar to a Venn
diagram, except that the population of each intersection is represented
by the width of a rectangle and a text representation of that population.
Thinking about it, maybe you are trying to represent both types of
individuals (that is, there exists more than one of individual type 1
and so on) and attributes (belonging to clusters). In this case you are
trying to get the intersections of two independent groups of sets.
So, I created a dataset in which individuals can have personal
characteristics (sex, age) and scholastic characteristics (which
subjects they study).
funnystuff<-data.frame(math=sample(c(0,1),100,TRUE),
biology=sample(c(0,1),100,TRUE),
english=sample(c(0,1),100,TRUE),
sex=sample(c(0,1),100,TRUE),
over18=sample(c(0,1),100,TRUE))
library(plotrix)
intersectDiagram(funnystuff,main="Studies by sex and age",sep="\n")
This gives me an interesting diagram from which I can get various
intersections of these two groups of attributes. Is this what you are
seeking?
Jim
More information about the R-help
mailing list