Hi:
here is one solution. Not so elegant but maybe it will give you some ideas:
mylist1<-rep(mylist,c(2,2))
a<-matrix(c(index1,!index1,index2,!index2),ncol=4)
mylist2<-list()
for (i in 1:4)
{
mylist2[[i]]<-mylist1[[i]][,a[,i]]
}
mylist2
Andrija
On Sun, Apr 3, 2011 at 6:56 PM, Axel Urbiz <axel.urbiz@gmail.com> wrote:
> Dear List,
>
> Let's say I have a list whose components are 2 matrices (as exemplified
in
> the "mylist" object below). I'd like to create a list with
components being
> 4 matrices based on an logical index vector. is there a way to simplify
> what
> I'm doing to obtain the results in "mylist2"? I'd like
something that would
> work on an arbitrary number of elements in "mylist".
>
> mylist <- list(matrix(1:9,3,3), matrix(10:18,3,3))
> index1 <- c(TRUE,FALSE,TRUE)
> index2<- c(FALSE,TRUE,TRUE)
> mylist2 <- list(mylist[[1]][,index1],
> mylist[[1]][,index1==FALSE],
> mylist[[2]][,index2],
> mylist[[2]][,index2==FALSE])
>
> Thanks in advance,
> Axel.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org 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.
>
[[alternative HTML version deleted]]