Skip to content
Prev 167383 / 398502 Next

select observations from longitudinal data set

Try this.  'by' splits up the data frame into one data frame
per id and then f acts separately on each such sub-dataframe
returning a ts series with NAs for the missings.  cbind'ing
those all together gives us this series with one column
per id:
Time Series:
Start = 1
End = 6
Frequency = 1
   1  2  3  4  5
1 10  8  8  9  7
2 12 NA NA NA  9
3 15  9 NA NA NA
4 NA 11 16 NA NA
5 NA 12 NA 13 NA
6 18 NA NA NA 11

and finally we use a string of ifelse's to choose the correct values.
1  2  3  4  5
15 11 16 13 NA

As in the example data, we have assumed that at least one of the
sub-dataframes has a point at time 1 and at least one has a
point at time 5.
On Sun, Jan 18, 2009 at 2:42 AM, gallon li <gallon.li at gmail.com> wrote: