[英]How to use rbind.data.frame such that the resulting data frame has no row names?
I have a list containing data frames that I want to merge into one big data frame without row names.我有一个包含数据框的列表,我想将这些数据框合并到一个没有行名称的大数据框中。 I tried:
我试过:
ls <- list(df1 = data.frame(col1 = c(1, 2)), df2 = data.frame(col1 = c(3, 4)))
do.call(rbind.data.frame, ls)
However, this leads to a data frame with row names:但是,这会导致带有行名称的数据框:
col1
df1.1 1
df1.2 2
df2.1 3
df2.2 4
I also tried do.call(rbind.data.frame(make.row.names = F), ls)
.我也试过
do.call(rbind.data.frame(make.row.names = F), ls)
。 But this earned me:但这为我赢得了:
Error in do.call(rbind.data.frame(make.row.names = F), ls) : 'what' must be a function or character string
do.call(rbind.data.frame(make.row.names = F), ls) 中的错误:'what' 必须是函数或字符串
EDIT: If no easy solution pops up, I will delete the row names in a second step with rownames(df_goal) <- c(0)
.编辑:如果没有简单的解决方案弹出,我将在第二步中使用
rownames(df_goal) <- c(0)
删除行名称。
dplyr::bind_rows(ls)
should give you the expected output. dplyr::bind_rows(ls)
应该给你预期的输出。
Option 2: Reduce(rbind.data.frame, ls)
选项 2:
Reduce(rbind.data.frame, ls)
Option 3 (for completeness) - suggested by @Henrik: do.call(rbind, c(ls, make.row.names = FALSE))
选项 3(为了完整性)-@Henrik 建议:
do.call(rbind, c(ls, make.row.names = FALSE))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.