有沒有一種最好的方法來提取列表的下層元素?
例如,此列表中的人有一系列「人物」,每個人物的編號爲「people[[i]]$Expertise$R
」。
有沒有最好的方法來提取它們作爲矢量?
我希望使用rlist和它的好處來加載我需要的東西,但是我看不到這個功能。
下面是一個例子做什麼,我需要,但可能未達最佳的:提取列表中的「lower」/「terminal」元素R
#https://renkun.me/rlist-tutorial/Features/Filtering.html
#install.packages("rlist")
library(rlist)
people <- list.load("http://renkun.me/rlist-tutorial/data/sample.json")
length(people)
str(people)
people[[1]][[1]]$R
str(list.filter(people, Age >= 25))
Rskill<-numeric()
for(i in 1:length(people))
Rskill<-c(Rskill,people[[i]]$Expertise$R)
Rskill
unlist(lapply(1:length(people),function(i) people[[i]]$Expertise$R))
請提供一個可重複的例子。 http://stackoverflow.com/q/5963269/1691723 – Sathish
@Sathish:OP的例子看起來可以重現給我 –
我不熟悉'rlist',但是你可以讓你的'lapply()'更簡單一些,更強大':vapply(people,function(p)p $ Expertise $ R,integer(1))' –