简体   繁体   中英

How can I get a element in list in R?

I am new to R, I want to get a element in a list which is element in another list, like this:

> a<-list(foo=1:4,bar=7:9) 
> a 
$foo
[1] 1 2 3 4

$bar 
[1] 7 8 9

How can I get the "3" in foo? In python, I use something like

a["foo"][1]

to get the element, but can anybody tell me the corresponding method in R?

另一个选择是$以名称提取list元素,然后使用[

a$foo[1]

use

a[[1]][[3]]

or

a[[c(1,3)]]

to get element 3 in foo.

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