Hi,
Try this:
dat1<- read.table(text="
ID??? COMPL? SEX? HEREDITY
1??? 0????? 1????? 2
1??? 0????? 1????? 2
1??? 3????? 1????? 2
2??? 0????? 0????? 1
2??? 1????? 0????? 1
2??? 2????? 0????? 1
2??? 2????? 0????? 1
3??? 0????? 0????? 1
3??? 0????? 0????? 1
3??? 0????? 0????? 1
3??? 0????? 0????? 1
3??? 2????? 0????? 1
4??? 0????? 1????? 2
4??? 0????? 1????? 2
",sep="",header=TRUE)
library(plyr)
dat2<- dat1[ddply(dat1,.(ID),summarise,COMPL!=0)[,2],]
?aggregate(.~ID,data=dat2,head,1)
#? ID COMPL SEX HEREDITY
#1? 1???? 3?? 1??????? 2
#2? 2???? 1?? 0??????? 1
#3? 3???? 2?? 0??????? 1
A.K.
----- Original Message -----
From: Tasnuva Tabassum <t.tasnuva at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Saturday, February 23, 2013 9:28 AM
Subject: [R] Selecting First Incidence from Longitudinal Data
I have a longitudinal competing risk data of the form:
ID? ? COMPL? SEX? HEREDITY
1? ? 0? ? ? 1? ? ? 2
1? ? 0? ? ? 1? ? ? 2
1? ? 3? ? ? 1? ? ? 2
2? ? 0? ? ? 0? ? ? 1
2? ? 1? ? ? 0? ? ? 1
2? ? 2? ? ? 0? ? ? 1
2? ? 2? ? ? 0? ? ? 1
3? ? 0? ? ? 0? ? ? 1
3? ? 0? ? ? 0? ? ? 1
3? ? 0? ? ? 0? ? ? 1
3? ? 0? ? ? 0? ? ? 1
3? ? 2? ? ? 0? ? ? 1
4? ? 0? ? ? 1? ? ? 2
4? ? 0? ? ? 1? ? ? 2.
Where, COMPL= health complication of diabetic patients which has value
labels? as? 0= no complication,1=coronary heart disease, 2=retinopathy, 3=
nephropathy.
I want to select only the first complication that occurred to each patient.
What R function can I use?
??? [[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.