john james
2008-Sep-16 14:01 UTC
[R] creating baseline variable from a longitudinal sequence
Dear R-help mailing list, Kindly help me out with this problem: I have a dataset that is in the format below, ID time Y Age 1 0 195 23.1 1 2 204 23.3 1 4 202 23.5 2 0 170 22.0 2 3 234 22.2 3 0 208 24.4 3 2 194 24 .7 3 3 204 24.9 I wish to remove all the measurements at time point 0 and convert them to a baseline variable as follows; ID time Y Age baseline 1 2 204 23.3 195 1 4 202 23.5 195 2 3 234 22.2 170 3 2 194 24 .7 208 3 3 204 24.9 208 Thanks. regards John [[alternative HTML version deleted]]
Peter Dalgaard
2008-Sep-16 17:06 UTC
[R] creating baseline variable from a longitudinal sequence
john james wrote:> Dear R-help mailing list, > ? > Kindly help me out with this problem: > ? > I have a dataset that is in the format below, > ID? time? Y? Age > 1? 0???? 195? 23.1 > 1? 2??? 204? 23.3 > 1? 4?? 202??? 23.5 > 2? 0? 170??? 22.0 > 2? 3?? 234?? 22.2 > 3? 0? 208?? 24.4 > 3? 2? 194? 24 .7 > 3? 3?? 204? 24.9 > ? > I wish to remove all the measurements at time point 0 and convert?them to a baseline variable as follows; > ? > ?ID? time? Y? Age? baseline > 1? 2??? 204? 23.3?? 195 > 1? 4?? 202??? 23.5?? 195 > 2? 3?? 234?? 22.2??? 170 > 3? 2? 194? 24 .7???? 208 > 3? 3?? 204? 24.9???? 208 >Something in your mail path (or mine) is inserting funny characters in your text, making it a bit hard to use the data for testing... Anyways, I'd split the data frame into the baseline values and the rest using subset() or maybe split(), rename the baseline variable(s) and then stick things together with merge() -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Henrique Dallazuanna
2008-Sep-16 17:11 UTC
[R] creating baseline variable from a longitudinal sequence
If DF is your data.frame: subset(cbind(DF, baseline=rep(DF$Y[DF$time == 0], table(DF$ID))), time > 0) On Tue, Sep 16, 2008 at 11:01 AM, john james <dntssa@yahoo.com> wrote:> Dear R-help mailing list, > > Kindly help me out with this problem: > > I have a dataset that is in the format below, > ID time Y Age > 1 0 195 23.1 > 1 2 204 23.3 > 1 4 202 23.5 > 2 0 170 22.0 > 2 3 234 22.2 > 3 0 208 24.4 > 3 2 194 24 .7 > 3 3 204 24.9 > > I wish to remove all the measurements at time point 0 and convert them to a > baseline variable as follows; > > ID time Y Age baseline > 1 2 204 23.3 195 > 1 4 202 23.5 195 > 2 3 234 22.2 170 > 3 2 194 24 .7 208 > 3 3 204 24.9 208 > > Thanks. > > regards > John > > > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@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. > >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]