Skip to content
Prev 178161 / 398502 Next

Generalized 2D list/array/whatever?

I cannot figure out what you are trying to do, but I'm reasonably sure  
that the construction:

xxx[[index,index2]] ... is going to fail. If you want to create a two  
dimensional structure, most people would use either a dataframe or a  
matrix rather than a list, although lists have the advantage that they  
do not need to be "pre-dimensioned". If you know what your dimension  
are in advance they are probably the way to go.

If you want to access multiple "dimensions" of a list, do not use  
[[ , ]] but rather [[ idx ]] to get the desired first "dimension" and  
then [ idx2 ] to the right of the expression for the first "dimension"  
to get or change the second "dimension", although "level" or "depth"  
might be the better terminology.

m <- list(sin, 1:3, letters[1:3], expression(a+b))
m[[2]][3]  ]
m[[2]][3] <- 8
m
m[[2]][3]

You have a better chance of getting on target advice if you explain  
what you want to do rather than showing us code patterned on another  
language that obviously doesn't work in R.
On Apr 23, 2009, at 10:29 PM, Toby wrote:

            
David Winsemius, MD
Heritage Laboratories
West Hartford, CT