> x
[[1]]
[1] "Bob" "John" "Tom"
[2] "Claire" "Betsy"
[[2]]
[1] "Strawberry" "Banana"
[2] "Kiwi"
[[3]]
[1] "Red"
[2] "Blue" "White"
假设我有一个清单x
如上图所示。我希望对列表中每个条目的第二个元素进行子集化
x[[1]][2]
x[[2]][2]
x[[3]][2]
我怎样才能用一个命令来做到这一点?我试过x[[1:3]][2]
但我得到一个错误。
Try
sapply(x2, `[`,2)
#[1] " from localhost (localhost [127.0.0.1])"
#[2] " from phobos [127.0.0.1]"
#[3] " from n20.grp.scd.yahoo.com (n20.grp.scd.yahoo.com"
#[4] " from [66.218.67.196] by n20.grp.scd.yahoo.com with NNFMP;"
data
x2 <- list(c("Received", " from localhost (localhost [127.0.0.1])"),
c("Received", " from phobos [127.0.0.1]"), c("Received",
" from n20.grp.scd.yahoo.com (n20.grp.scd.yahoo.com"),
c("Received", " from [66.218.67.196] by n20.grp.scd.yahoo.com with NNFMP;" ) )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)