[R] unequal number of observations for longitudinal data

From: gallon li <gallon.li_at_gmail.com>
Date: Sat 27 Jan 2007 - 10:34:40 GMT


i have a large longitudinal data set. The number of observations for each subject is not the same across the sample. The largest number of a subject is 5 and the smallest number is 1.

now i want to make each subject to have the same number of observations by filling zero, e.g., my original sample is

id x
001 10
001 30
001 20
002 10
002 20
002 40
002 80
002 70
003 20
003 40
004 ......

now i wish to make the data like

 id x
001 10
001 30
001 20
001 0

001 0
002 10
002 20
002 40
002 80
002 70
003 20
003 40
003 0
003 0
003 0
004 ......

so that each id has exactly 5 observations. is there a function which can allow me do this quickly?

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch 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. Received on Sat Jan 27 21:38:49 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 27 Jan 2007 - 11:30:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.