Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从列表列表中提取数据[R]_R_List_Lapply - Fatal编程技术网

从列表列表中提取数据[R]

从列表列表中提取数据[R],r,list,lapply,R,List,Lapply,我有一个列表(mydata$notes),我想从中提取数据。代码看起来像这样,如果我想提取“位置”-这很好 location <- unlist (lapply(mydata$notes, function(e) e$location)) 如何循环我的第一个代码来提取这个变量名中给出的所有变量 Cheers定义一个向量来保存要提取的列表元素。然后对调用lappy()处理的每个列表调用unlist() vars谢谢!但现在我的“位置”变量是一个字符。我想返回一个矩阵或数据框,其中包含“va

我有一个列表(mydata$notes),我想从中提取数据。代码看起来像这样,如果我想提取“位置”-这很好

location <- unlist (lapply(mydata$notes, function(e) e$location))
如何循环我的第一个代码来提取这个变量名中给出的所有变量


Cheers

定义一个向量来保存要提取的列表元素。然后对调用
lappy()
处理的每个列表调用
unlist()

vars谢谢!但现在我的“位置”变量是一个字符。我想返回一个矩阵或数据框,其中包含“vars”中指定的元素。我该怎么做?请看如何做。
names(unlist(mytree$notes[[1]]))
vars <- c("location", "var1", "var2", "var3")

location <- unlist (lapply(mydata$notes,
                           function(e) {
                               unlist(e[vars])
                           }))