HI,
It is better to dput() an example dataset to work with.
May be this helps:
dat1<-read.table(text="
ID?? Diag?? Proc? DOB? Gender??
a??? diag1??? 1?? 10/15/1969 M?
b??? diag2??? 2??? 8/25/1978 F
c??? diag1??? 1??? 1/10/1985 M
a??? diag3??? 3??? 10/15/1969 M
b??? diag4??? 4??? 8/25/1978 F
b??? diag4??? 5??? 8/25/1978 F
",sep="",header=TRUE,stringsAsFactors=FALSE)
library(reshape)
res<-reshape(dat1,idvar=c("ID","DOB","Gender"),v.names="Diag",timevar="Proc",direction="wide")
?res
#? ID??????? DOB Gender Diag.1 Diag.2 Diag.3 Diag.4 Diag.5
#1? a 10/15/1969????? M? diag1?? <NA>? diag3?? <NA>?? <NA>
#2? b? 8/25/1978????? F?? <NA>? diag2?? <NA>? diag4? diag4
#3? c? 1/10/1985????? M? diag1?? <NA>?? <NA>?? <NA>??
<NA>
?
A.K.
----- Original Message -----
From: farnoosh sheikhi <farnoosh_81 at yahoo.com>
To: "r-help at R-project.org" <r-help at r-project.org>
Cc:
Sent: Tuesday, November 6, 2012 3:37 PM
Subject: [R] pivot table
Hello,
I have a data which looks like below: Some of the patients have multiple
diagnosis.
ID(200 patients) ? Diag (100 unique Diag-200 in general) ? Proc (50 uniqe Proc)
?DOB (200) ? Gender (200) ??
a ? ? ? ? ? ? ? ? ? ? ? ? ? daig1
b ? ? ? ? ? ? ? ? ? ? ? ? ? diag2
c ? ? ? ? ? ? ? ? ? ? ? ? ? ?diag1
I want to reformat this data to :
ID ? diag1 diag 2 diag 3.. ?diagx ? proc1 ? proc2 ? proc3... procx ?DOB ?Gender
a1011? 20F
Thanks a lot for your help and time.
?
Best,Farnoosh Sheikhi
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.