如何在R中将选定的子列表合并到一个数据帧中?

如何在R中将选定的子列表合并到一个数据帧中?,r,R,这是我正在研究的3种植物的子集 spp <- c("Shorea robusta Gaertn.", "Schima wallichii (DC.) Korth.", "Terminalia alata Roth") spp您可以尝试do.call(rbind,…)例程: do.call(rbind, lapply(test.rgbif[spp], function(df) df$data)) 如果data.frames具有不同的列或列顺序,dplyr::bind_rows更合适,因

这是我正在研究的3种植物的子集

spp <- c("Shorea robusta Gaertn.", "Schima wallichii (DC.) Korth.", 
"Terminalia alata Roth")

spp您可以尝试
do.call(rbind,…)
例程:

do.call(rbind, lapply(test.rgbif[spp], function(df) df$data))
如果
data.frame
s具有不同的列或列顺序,
dplyr::bind_rows
更合适,因为它将通过列名匹配:

do.call(bind_rows, lapply(test.rgbif[spp], function(df) df$data))

我不能尝试,但下面的方法可以做到

library(magrittr)
library(purrr)
library(data.table)

test.rgbif %>% 
  # turns list of length 3 with 2 elements each into a 
  # list of 2 with 3 elements each
  purrr::transpose %>%
  # take the data list-entry
  .$data %>% 
  # and rbind its 3 elements
  rbindlist(idcol = "Species")
*:我得到以下错误

> test.rgbif <- ...
Error in check_wkt(geometry) : 
  bad lexical cast: source type value could not be interpreted as target at '
' in 'polygon ((78.0074716700000010 24.5425829399999991, 
                       78.0074716700000010 32.25'

>test.rgbif您是在寻找类似于
test.rgbif[,spp[1]]的东西吗谢谢mt1022提供的有用答案,因为我的数据帧(子列表)具有不同的维度,绑定行比rbind更适合我的需要,即do.call(bind_rows,lappy(test.rgbif[spp],function(df)df$data))@R-fander,当然<代码>绑定_行
对于输入数据帧更灵活。我从不使用rgbif,所以我真的不知道实际数据是什么样子。亲爱的用户22966153,我不知道您为什么会收到这样的错误,但它只是WKT文件来定义我感兴趣的领域的范围。无论如何,谢谢你的回答。由于您的答案涉及到安装新软件包,所以我这次将坚持使用mt1022的答案,这是直截了当的。
> test.rgbif <- ...
Error in check_wkt(geometry) : 
  bad lexical cast: source type value could not be interpreted as target at '
' in 'polygon ((78.0074716700000010 24.5425829399999991, 
                       78.0074716700000010 32.25'