[R] placing multiple rows in a single row

Annemarie Verkerk annemarie.verkerk at mpi.nl
Mon Jul 4 20:32:37 CEST 2011


Dear people from the R help list,

I have a question that I can't get my head around to start answering, 
that is why I am writing to the list.

I have data in a format like this (tabs might look weird):

John     A1     1     0     1
John     A2     1    1    1
John     A3     1    0    0
Mary    A1     1     0     1
Mary     A2     0    0    1
Mary     A3    1    1    0
Peter     A1     1    0    0
Peter     A2     0    0    1
Peter     A3     1    1    1
Josh     A1     1     0    0
Josh     A2
Josh     A3    0    0    0

I want to convert it into a format where variable rows from a single 
subject are placed behind each other, but with the different scores 
still matching up (i.e., it needs to be able to cope with missing data, 
as for Josh's A2 score).

John     A1     1     0     1     A2     1    1    1     A3     1    0    0
Mary    A1     1     0     1    A2     0    0    1     A3    1    1    0
Peter     A1     1    0    0     A2     0    0    1     A3     1    1    1
Josh     A1     1     0    0      A2                A3    0    0    0

Preferably, the row identification would become the header of the new 
table, something like this:

        A11    A12    A13 A21    A22    A23    A31    A32    A33
John      1     0     1      1    1    1      1    0    0
Mary     1     0     1     0    0    1     1    1    0
Peter      1    0    0      0    0    1      1    1    1
Josh      1     0    0                  0    0    0

Probably, this has been addressed before - I just don't know how to 
search for the answer with the right search terms.

Any help is appreciated, even just a link to a page where this is addressed!

Thank you!
Annemarie

-- 
Annemarie Verkerk, MA
Evolutionary Processes in Language and Culture (PhD student)
Max Planck Institute for Psycholinguistics
P.O. Box 310, 6500AH Nijmegen, The Netherlands
+31 (0)24 3521 185
http://www.mpi.nl/research/research-projects/evolutionary-processes



More information about the R-help mailing list