Say I have a list of 3 Matrices. How do I extract one of the matrices as a Matrix-Object, so I can further access it's elements with mymatrix[i,j]
calls?
mylist[i]
simply returns a List-Object with Matrix i
.
I'm sure there has to be a simple solution, but I couldn't manage to find one.
use double brackets: mylist[[i]]
....
From ?"[["
(emphasis added):
Recursive (list-like) objects:
Indexing by '[' is similar to atomic vectors and selects a list of the specified element(s) .
Both '[[' and '$' select a single element of the list . The main difference is that '$' does not allow computed indices,
mylist[[1]]
should return you the first matrix
mylist[[3]]
should return you the third matrix
If you want to automate this you could simply run:
for (index in 1:length(mylist)){
assign(paste0("matrix", index), mylist[[index]], envir = .GlobalEnv)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.