[R] problems with index within a strata

From: Vumani Dlamini <dvumani_at_hotmail.com>
Date: Mon, 28 May 2007 07:18:32 +0000

dear useRs,
I have several datasets which are in repeated measurements format and I would like to extract the first measurement for each individual. In some cases measurements of certain characteristics are also stacked on top of each other and thats where the problem lies. A prototype of the code I use is as follows,

# If I am extracting the first element for each individual (works fine)
temp <- sort(rpois(100,2.5))
temp.tab <- as.vector(table(temp))
cbind(temp,unlist(lapply(1:length(temp.tab), function(i){1:temp.tab[i]})))

# If I am extracting the first element of a variable for each individual
(doesn't work)

temp.0 <- sort(rpois(100,2.5))
temp.1 <- rbinom(100,1,0.25)
temp.tab <- as.vector(t(table(temp.0,temp.1)))
cbind(temp,unlist(lapply(1:length(temp.tab), function(i){1:temp.tab[i]})))

I don't understand why the first works ok and the second fails. "sum(temp.tab)" is still the same.
Thanks for your help,

R-help_at_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 Mon 28 May 2007 - 07:23:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 May 2007 - 07:31:43 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.