Anshuman Kirty
Anshuman Kirty

Reputation: 176

Accessing data in r from list with multiple vectors

A <- list(X = c(Z = 15))

How do I access 15 in the above example

Upvotes: 0

Views: 153

Answers (3)

NelsonGon
NelsonGon

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

s_baldur
s_baldur

Reputation: 33743

Can also access it with indices:

A[[c(1, 1)]] 

Upvotes: 1

Tim Biegeleisen
Tim Biegeleisen

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

Related Questions