Why can't I get an element of this list in R? -


i have list l composed of following elements:

> l $quad_freqs             [,1]        [,2]       [,3]       [,4]       [,5]      [,6] sol 0.0002308597 0.004155474 0.00623358 0.02493248 0.02576132 0.0748037           [,7]      [,8]       [,9]     [,10]     [,11] sol 0.02493029 0.2318451 0.05612928 0.3593334 0.1916445 

i know l list because typed

> class(l) [1] "list" 

however, can't elements of list. example,

> l[[1]]             [,1]        [,2]       [,3]       [,4]       [,5]      [,6] sol 0.0002308597 0.004155474 0.00623358 0.02493248 0.02576132 0.0748037           [,7]      [,8]       [,9]     [,10]     [,11] sol 0.02493029 0.2318451 0.05612928 0.3593334 0.1916445 > l[[2]] error in l[[2]] : subscript out of bounds > l[[0]] error in l[[0]] : attempt select less 1 element 

i tried single bracket operator, didn't work either:

> l[2] $<na> null  > l[0] named list() 

how can elements of list?

this first time using r, sorry if stupid question.

from way l gets printed, appears 1 element list first (only) element one-row matrix. this:

l <- list(quadreps=matrix(rnorm(5), nrow=1)) l # $quadreps #           [,1]       [,2]      [,3]      [,4]      [,5] # [1,] 0.5060329 -0.6333043 0.6637485 0.7293132 -1.330237 

to access elements of matrix, need first extract list, using either $ or [[]], , further subset it. extract element in quadrep's third column, instance, use of following:

l$quadreps[1,3] # [1] -0.9604139  l[["quadreps"]][1,3] # [1] -0.9604139  l[[1]][1,3] # [1] -0.9604139 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -