0
votes

This might be very trivial, but I haven't found an answer yet (and I'm quite new to R).

I have a list containing a bunch of matrices. Each matrix in the list has the same number of rows and rownames.

How to I access say, the second row of each matrix in the list?

1
post some code of how you are trying to resolve this. You will recive more suggestionsmanuerumx

1 Answers

1
votes

Use lapply

x <-matrix(1:9, 3, dimnames=list(LETTERS[1:3], letters[24:26])) # creating a matrix

mylist <- list(x, 2*x, 3*x, 4*x) # creating the list

lapply(mylist, function(x) x['B',])  # By name
sapply(mylist, function(x) x['B',])  # alternative

lapply(mylist, function(x) x[2,])  # By index
sapply(mylist, function(x) x[2,])