In data OME in MASS I would like to extract the first 5 observations per 
subject (=ID). So I do
 
library(MASS)
OMEsub <- split(OME, OME$ID)
OMEsub <- lapply(OMEsub,function(x)x[1:5,])
unsplit(OMEsub, OME$ID)

- which results in 
 
[[1]]
[1] 1 1 1 1 1
[[2]]
[1] 30 30 30 30 30
[[3]]
[1] low low low low low
Levels: N/A high low
[[4]]
[1] 35 35 40 40 45
[[5]]
[1] coherent   incoherent coherent   incoherent coherent  
Levels: coherent incoherent
[[6]]
[1] 1 4 0 1 2

............
 
[[1094]]
[1] 4 5 5 5 2
[[1095]]
[1] 100 100 100 100 100
[[1096]]
[1] 18 18 18 18 18
[[1097]]
[1] N/A N/A N/A N/A N/A
Levels: N/A high low
There were 50 or more warnings (use warnings() to see the first 50)

warnings()
Warning messages:
1: number of items to replace is not a multiple of replacement length
2: number of items to replace is not a multiple of replacement length
3: number of items to replace is not a multiple of replacement length
....
 
According to documentation unsplit is the reverse of split, but I must be 
missing a point somewhere... Can anyone help? Thanks in advance. Søren

______________________________________________
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

Reply via email to