Skip to content
Prev 178190 / 398503 Next

Generalized 2D list/array/whatever?

Toby wrote:
What you have there is not legal syntax, but this would be:

x[[c("some label", "some other index")]] <- 3

This assumes that x is a list, and one of its entries is a list named 
"some label".  It will not create that entry, but it will create an 
entry named "some other index", so you need

if (is.null(x[["some label"]])) x[["some label"]] <- list()

first.  After executing this line and your first line above, you'll get

 > x
$`some label`
$`some label`$`some other index`
[1] 3

Duncan Murdoch