[R] Filling in a series

From: Dennis Fisher <fisher_at_plessthan.com>
Date: Sat 21 Oct 2006 - 13:22:36 GMT

Colleagues

After reading in some clinical data, I discovered that the subject ID column contains entries only for the first record for each individual; subsequent rows are recorded as NA. For example:
> 1
> NA
> NA
> NA
> NA
> 2
> NA
> NA
> NA
> NA
> 3
> NA
> NA
> ...

I can think of various approaches to replace the NA values with appropriate entries. I could loop through each row - if the value is NA, I replace it with the entry from the row above. Or, I could find the positions of the non-NA values with match, then replace groups of entries (e.g., positions 2-5) with appropriate entries, again with a loop.

But, I expect that R allows some more clever approach to the problem. Any thoughts?

Dennis

Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-415-564-2220
www.PLessThan.com

        [[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 Sun Oct 22 05:55:46 2006

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 21 Oct 2006 - 20:30:40 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.