我正在尝试一个接一个地组合数据框
df1 df1
name address age Gender
A NY 23 M
B CA 22 F
33 M
39 F
我正在尝试将数据框与下面的代码组合在一起,这些代码没有提供所需的输出
folder <- "path/" # path to folder shows multiple .csv files
file_list <- list.files(path=folder, pattern="*.csv") # create list of all .csv files in folder
all_df <-
do.call("cbind",
lapply(file_list, function(x) read.csv(paste(folder, x, sep=''), stringsAsFactors = FALSE)))
O / P
all_df
name address age Gender
A NY 23 M
B CA 22 F
33 M
39 F
答案 0 :(得分:0)
我们可以使用cbind.fill
rowr
library(rowr)
cbind.fill(df1, df2, fill="")
# name address age Gender
#1 A NY 23 M
#2 B CA 22 F
#3 33 M
#4 39 F
如果我们想修改OP的原始代码
do.call(cbind.fill,
lapply(file_list, function(x) read.csv(paste(folder, x, sep=''), stringsAsFactors = FALSE)))