Reputation: 176
A <- list(X = c(Z = 15))
How do I access 15 in the above example
Upvotes: 0
Views: 153
Reputation: 13319
You can simply do:
A[[1]]
This gets the first "component" of the list.
A[[1]]
Z
15
Or if you want to go step by step, then:
A[1][[1]]
Z
15
Upvotes: 0
Reputation: 522752
We can try using a combination of list access syntax along with vector access syntax:
A <- list(X = c(Z = 15))
A$X["Z"]
Z
15
Above A$X
refers to the element in the list named X
, which happens to be a vector. Then, A$X["Z"]
accesses the element in the vector named Z
, which is the value 15.
Upvotes: 1