[R] Accessing matrix elements within a list

Maria P Petrova mpetrova at u.washington.edu
Fri Jun 25 23:29:40 CEST 2010


Hi there, 

I cannot seem to figure out how to access the elements of a list if those elements are a matrix.
For example I have a the following list
 
df.list <- vector("list", 3)
and I have made each of the elements a matrix as follows

for(i in 1:3){
 assign(paste("s",i, sep=""),matrix(0, nrow = 20, ncol = 5, byrow
= FALSE, dimnames = NULL))
}

# and then insert them with a loop like this

# put matrices names in a vector
matrices<-c("s1","s2","s3") 

# insert
for(i in 1:3){
df.list[[i]] <- matrices[i]
}

My question is I cannot access the first rwo of the matrix within a list. The following does not work

df.list [[1]][1,]

Thanks for your help!



More information about the R-help mailing list