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?
df1 = data.frame(V1 = c(1, 2), V2 = c(3, 4))
df2 <- data.frame(V1 = 2, V2 = 3)
df1[nrow(df1) + 1:nrow(df2), ] <- df2
我们可以通过在提取'df2'的第一列后在'df1'中创建新行来进行分配
df1[nrow(df1)+1, ] <- df2[[1]]
df1
# V1 V2
#1 1 3
#2 2 4
#3 2 3
注意:OP显示的数据集'df2'仅包含一列。假定该列中的行数等于'df1'
中的列数