Question

I have created a list of multiple matrices called 'Mix' and I need to subset all the matrices in the list to the same number of rows and columns (5:1, 5:20). I tried this but it didn't work:

NM<-lapply(Mix, subset(c(5:31,5:20)))

I also tried :

NM<-lapply(Mix, subset(c[5:31],c[5:20]))

It still did not work. What would be the best options to subset all the matrices in Mix?

Was it helpful?

Solution

Posting as answer, to close out the question:

NM <-lapply(Mix, function(x) x[5:31,5:20]) 

#To merge them into one matrix
NM <- do.call("rbind",NM)

#To check size of each matrix/subset
do.call('rbind', lapply(Mix, dim))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top