[R] Help reshaping a dataset with multiple tuples per row

arun smartpink111 at yahoo.com
Wed Feb 20 00:17:07 CET 2013

Try this:
dat1<- read.table(text="
Patient  Treatment Outcome  Advice Treatment  Outcome  Advice
P1        T1              O1          A1        T2            O2          A2

row.names(res)<- 1:nrow(res)
 res<- res[,-c(2,6)]
 # Patient Treatment Outcome Advice
#1      P1        T1      O1     A1
#2      P1        T2      O2     A2


----- Original Message -----
From: Jim Underwood <droolinggeezer at gmail.com>
To: r-help at r-project.org
Sent: Tuesday, February 19, 2013 5:29 PM
Subject: [R] Help reshaping a dataset with multiple tuples per row

I have a dataset which contains several multi-column measurement sets per row. 
Col 1 identifies patient:

Col1        Col2            Col3          Col 4    Col 5             Col 6       Col7   ...
Patient   Treatment  Outcome  Advice  Treatment  Outcome  Advice
"P1"         "T1"              "O1"          "A1"        "T2"            "O2"          "A2"

Please advise a reshape strategy to generate an output frame with a single measurement per row, e.g.,

Col1        Col2          Col3        Col4
Patient  Treatment Outcome Advice
"P1"         "T1"              "O1"          "A1" 
"P1"         "T2"              "O2"          "A2"
R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list