Skip to content

pivot table help

5 messages · set, Richard M. Heiberger, jim holtman

set
#
Hello R-users,

I've got a huge table with about 20.00 rows and 50 columns. The table now
has headers as Members1, Members2 etc. My data are 8 different individuals.
And I've got a column with clusters. So each individual belongs to different
clusters and can occurs multiple times within a cluster (that's the reason
that there can be more than 8 members). I want a presence/ absence table for
each individual within each cluster.
So I want to go from:
Cluster   Member1    Member2  etc.
1            ind1           ind2
2            ind3           ind1
3            ind2           ind1

to

cluster    ind1          ind2      ind3
1            1               1          0
2            1                0         1
3            1               1          0

Has anybody any idea how I can do this? I already tried alot of things with
pivottables (using cast()) But I think I'm missing out on something.
thank you

--
View this message in context: http://r.789695.n4.nabble.com/pivot-table-help-tp4155144p4155144.html
Sent from the R help mailing list archive at Nabble.com.
#
try this:
+ 1            ind1           ind2
+ 2            ind3           ind1
+ 3            ind2           ind1", as.is = TRUE, header = TRUE)
Cluster variable value
1       1  Member1  ind1
2       2  Member1  ind3
3       3  Member1  ind2
4       1  Member2  ind2
5       2  Member2  ind1
6       3  Member2  ind1
ind1 ind2 ind3
  1    1    1    0
  2    1    0    1
  3    1    1    0

        
On Sat, Dec 3, 2011 at 5:53 PM, Richard M. Heiberger <rmh at temple.edu> wrote:

  
    
#
Forgot, you can also do this:
Cluster ind1 ind2 ind3
1       1    1    1    0
2       2    1    0    1
3       3    1    1    0

        
On Sat, Dec 3, 2011 at 7:02 PM, jim holtman <jholtman at gmail.com> wrote: