如何在不重写整个数据框的情况下在现有数据框的底部加入数据框?

How to join a data frame at the bottom of an existing one without rewriting the whole?

df1 = data.frame(c(1,2),c(3,4))
colnames(df1) = c("V1","V2")

df2 = data.frame(c(2,3),c(5,6))
colnames(df2) = c("V1","V2")

如何在不使用需要重新写入整个数据帧的 rbind 的情况下在 df1 底部添加 df2?

我们可以通过在提取 'df2'

的第一列后在 'df1' 中创建一个新行来进行赋值
df1[nrow(df1)+1, ] <- df2[[1]]
df1
#  V1 V2
#1  1  3
#2  2  4
#3  2  3

注意:OP 显示了一个只有一列的数据集 'df2'。假定该列中的行数等于 'df1'

中的列数

有了新的数据集,我们可以使用

df1[nrow(df1) + seq_len(nrow(df2)),] <- df2