Extract elements from a List

Asked

Viewed 365 times

5

I have this list:

a <- list()
  a[[1]] <- matrix(c(1,2),nrow = 2)

How do I select element 2 ?

1 answer

3


To access the matrix element 2 in the list first you have to access the matrix -- a[[1]] because it is the first element of the list -- and then access the second element of the matrix -- a[[1]]][[2]] or a[[1]][2].

a[[1]][[2]]
[1] 2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.