简体   繁体   中英

Accessing data in r from list with multiple vectors

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

在上面的示例中如何访问15

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.

也可以通过索引访问它:

A[[c(1, 1)]] 

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM