Dear R users,
Let's say I have a list with components being 'm' matrices (as exemplified
in the "mylist" object below). Now, I'd like to subset this list based on an
index vector, which will partition each matrix 'm' in 2 sub-matrices. My
questions are:
1. Is there an elegant way to have the results shown in mylist2 for an
arbitrary number of matrices in mylist?
2. The column names are 'lost' for mylist2[[2]] and mylist2[[4]] (but not
for mylist2[[1]] and mylist2[[3]]). Is there a way to keep
the column names in the results of mylist2?
mylist <- list(matrix(1:9,3,3), matrix(10:18,3,3))
colnames(mylist[[1]])=c('x1','x2','x3')
colnames(mylist[[2]])=c('x4','x5','x6')
index <- list(2)
index[[1]] <- c(TRUE,FALSE,TRUE)
index[[2]] <- c(FALSE,TRUE,TRUE)
mylist2 <- list(as.matrix(mylist[[1]][,index[[1]]]),
as.matrix(mylist[[1]][,!index[[1]]]),
as.matrix(mylist[[2]][,index[[2]]]),
as.matrix(mylist[[2]][,!index[[2]]]))
Thanks for any help,
Axel.
[[alternative HTML version deleted]]