尊敬的亲爱的社区,
在这篇文章之后,
我正在搜索如何从包含多个具有不同名称的子列表的列表中创建多个数据框
因此,从名单中tier.col 我想创建一个函数tier2col,该函数返回多个data.frames(与我的列表中的子列表一样多),其中包含子列表的特定元素.
我得到如何手动执行此操作:
phones <- data.frame(tier.col$phones$xmin[-1,3], tier.col$phones$xmax[-1,3], tier.col$phones$text[3])
Run Code Online (Sandbox Code Playgroud)
但实际上"手机"会改变多个名称,因此我需要一种更通用的方法来制作子列表:
x <- data.frame(tier.col$x$xmin[-1,3], tier.col$x$xmax[-1,3], tier.col$x$text[3])
Run Code Online (Sandbox Code Playgroud)
该功能将如下:
tier2col <- function(list.x) {
for all sublist in my list
select tier.col$sublist$xmin[-1,3], tier.col$sublist$xmax[-1,3], tier.col$sublist$text[3]
and compile them in a dataframe
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过这个调用所有的xmin&xmax&text:
lapply(tier.col[c(1:length(names(tier.col)))], "[", 1)
lapply(tier.col[c(1:length(names(tier.col)))], "[", 2)
lapply(tier.col[c(1:length(names(tier.col)))], "[", 3)
但我不知道如何通过这种或如何在这种数据结构上使用mapply.
我希望有类似的tier.col$c(names(tier.col)$xmin工作,但显然,这不是正确的方法.
有人可以帮助我以有效的方式计算这个吗?
结构tier.col:
List of 17
$ phones :List of 3
..$ xmin:'data.frame': 2506 obs. of 3 …Run Code Online (Sandbox Code Playgroud)