r - 我想使用 rbind 绑定多个数据框
问题描述
我想绑定五个数据框 df1、df2、df3、df4 和 df5。但是,使用 fast.rbind() 返回错误说
找不到 fast.rbind()。
解决方案
您可以尝试以下方法 -
#get the 5 dataframes in a list
list_df <- mget(paste0('df', 1:5))
#Get the common column names
common_cols <- Reduce(intersect, lapply(list_df, colnames))
#select only the common columns from each dataframe and bind it to one dataframe.
result <- purrr::map_df(list_df, `[`, common_cols)
或者最后一步可以改为
result <- do.call(rbind, lapply(list_df, `[`, common_cols))
将所有内容保留在基础 R 中。
推荐阅读
- ios - SwiftUI: Scaling in Xcode is not the same as on my iPhone
- mips - buildroot,how to set the host platform architecture
- html - Position div under absolute positioned div
- angular - Prime-ng - Get the checked rows from p-table in button click in angular
- angular - Typescript generic type instantiation
- google-apps-script - 用于检索文件夹中所有文档的注释、突出显示的文本和文档名称的 Google 表格脚本
- python - How to segment the cloth area in the image using python opencv
- python - Streamlit Multiple Page UI - Page content retaining on using sliders
- c++ - Windows Filtering Platform sample program didn't work
- c - Expected an identifier - C