I have the following longitudinal data:

id time y
1 1 10
1 2 12
1 3 15
1 6 18
2 1 8
2 3 9
2 4 11
2 5 12
3 1 8
3 4 16
4 1 9
4 5 13
5 1 7
5 2 9
5 6 11
....

I want to select the observations at time 4. if the observation at time 4 is
missing, then i want to slect the observation at time 3. if the observation
at time 3 is also missing, then i want to select observation at time 5.
otherwise i will put a missing value there. the selected set is like

id time y
1 3 15
2 4 11
3 4 16
4 5 13
5 4 NA
...

so the rule is (1) obs at time 4 for each id; (2) if no such obs, then look
for obs at time 3; (3) if no such obs, then look for obs at time 5; (4)
otherwise, NA.

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

Reply via email to