Search code examples
rlistmatrixextract

How do I extract elements of a martix from a list in r?


I have a list composed by a vector and a matrix. I want to extract the element (3,2) of the matrix from the list. How do I do that?

mymatr <- matrix(1:10 , nrow = 5) 
myvecto <- 1:5
mylist <- list(myvecto, mymatr)

Solution

  • Code:

     > mylist[[2]][3,2]
    

    Output:

    8