Re: [R] subsetting a list of matrices

2011-08-23 Thread Justin Haynes
His is better, but you can also use a for loop... out<-data.frame(rows=1:3) for(i in 1:3){ if(l[[i]][3]=='Message 1') { out$V1[i]<-l[[i]][1] } else { out$V1[i]<-NA } } but shouldn't if your list is very long On Tue, Aug 23, 2011 at 9:35 AM, Henrique Dallazuanna wrote: > Try this:

Re: [R] subsetting a list of matrices

2011-08-23 Thread Henrique Dallazuanna
Try this: subset(as.data.frame(do.call(rbind, lapply(l, "[", , 1))), row3 == "Message 1") On Tue, Aug 23, 2011 at 1:28 PM, Lara Poplarski wrote: > Hi all, > > I have an object that looks (roughly) like the following: > > l <- list(a = matrix(rnorm(9), 3), b = matrix(rnorm(9), 3), c = > matrix(rn

[R] subsetting a list of matrices

2011-08-23 Thread Lara Poplarski
Hi all, I have an object that looks (roughly) like the following: l <- list(a = matrix(rnorm(9), 3), b = matrix(rnorm(9), 3), c = matrix(rnorm(9), 3)) l$a[3,] <- sample(c("Message 1", "Message 2", "Message 3")) l$b[3,] <- sample(c("Message 1", "Message 2", "Message 3")) l$c[3,] <- sample(c("Mess