[R] problems with index within a strata
Vumani Dlamini
dvumani at hotmail.com
Mon May 28 09:18:32 CEST 2007
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,
Vumani
More information about the R-help
mailing list