[R] Selecting n observation
bibek sharma
mbhpathak at gmail.com
Thu Oct 11 21:48:29 CEST 2012
Hello R help,
I have a question similar to what is posted by someone before. my
problem is that Instead of last assessment, I want to choose last two.
I have a data set with several time assessments for each participant.
I want to select the last assessment for each participant. My dataset
looks like this:
ID week outcome
1 2 14
1 4 28
1 6 42
4 2 14
4 6 46
4 9 64
4 9 71
4 12 85
9 2 14
9 4 28
9 6 51
9 9 66
9 12 84
Here is one solution for choosing last assessment
do.call("rbind",
by(df, INDICES=df$ID, FUN=function(DF) DF[which.max(DF$week), ]))
ID week outcome
1 1 6 42
4 4 12 85
9 9 12 84
More information about the R-help
mailing list