【发布时间】:2016-05-05 10:57:04
【问题描述】:
我是 R 新手,但遇到了问题。我创建了一个“空”data.frame,因为在 R 中我不能这样做,我创建了一个向量来实现它,我会在完成脚本时删除它。
x <- c("aa", 0, 0, 0, "zz") #Vector to fulfill the dataframe (it will be deleted at the end of the script)
df <<- rbind(x) #Creating a matrix. See: class(df)
df <<- data.frame(df) #Converting the matrix into a data.frame
但是现在我需要用三个向量来完成那个数据框:
a <- c("bb")
b <- c(2, 3, 4)
c <- c("yy")
所需的输出是这样的数据框:
X1 X2 X3 X4 X5
r1 aa 0 0 0 zz
r2 bb 2 3 4 yy
我试过这个:df <- rbind(df, a, b, c) 但它不起作用...
有什么建议吗?
【问题讨论】: