如何将表绑定到列中

时间:2015-06-19 17:38:57

标签: r

我有下表delete

  complete    creditcheck     disclosure    getduedates        package        payment        probing serviceability 
         1              2              3              3              2              2              1              1 

如何将这些列添加到我的数据框data_frame

假设data_framedelete具有相同的行数。

1 个答案:

答案 0 :(得分:0)

尝试

library(dplyr)
bind_rows(df1, as.data.frame.list(delete))
# Source: local data frame [4 x 3]

#   A  B  C
#1  1  4  7
#2  2  5  8
#3  3  6  9
#4 10 10 10

如果您需要cbind,请删除'使用现有列

bind_cols(df2, as.data.frame.list(delete))
#  V1 V2 V3  A  B  C
#1  1  2  3 10 10 10

数据

df1 <- data_frame(A=1:3, B=4:6, C=7:9)
b <- factor(rep(c("A","B","C"), 10))
delete <- table(b)
df2 <- data_frame(V1= 1, V2=2, V3=3)