[R] manipulating longitudinal data in r

arun smartpink111 at yahoo.com
Sat Nov 17 17:10:40 CET 2012


HI,
Try this:
 ke$b<-ave(ke$a,ke$patid,FUN=max)
 ke
#  patid a b
#1     1 1 2
#2     1 2 2
#3     1 2 2
#4     2 1 1
#5     3 1 2
#6     3 2 2
A.K.




----- Original Message -----
From: Kemi Racheal <kemiadeboye2002 at yahoo.com>
To: R-help at r-project.org
Cc: 
Sent: Saturday, November 17, 2012 3:56 AM
Subject: [R] manipulating longitudinal data in r

Dear list member,

I have the following data example
ke <- data.frame(patid=c(1,1,1,2,3,3),a=c(1,2,2,1,1,2))

I want to add another variable b, such that the max of 'a' by id is returned
i.e data ke becomes
ke <- data.frame(patid=c(1,1,1,2,3,3),a=c(1,2,2,1,1,2),b=c(2,2,2,1,2,2))

Any help will be appreciated.

Oluwakemi


    [[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.





More information about the R-help mailing list