Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R-将一列数据添加到数据帧中的现有列中_R_Dataframe - Fatal编程技术网

R-将一列数据添加到数据帧中的现有列中

R-将一列数据添加到数据帧中的现有列中,r,dataframe,R,Dataframe,我试图找出如何将更多数据一次一列地附加到现有数据帧中。例如:我有这个数据帧: df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789)) 追加数据时,需要确保列名相同 就你而言: df2 <- data.frame(x2, y2) #creating a dataframe names(df2) <- names(df) #changing the col

我试图找出如何将更多数据一次一列地附加到现有数据帧中。例如:我有这个数据帧:

df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789))

追加数据时,需要确保列名相同

就你而言:

df2 <- data.frame(x2, y2)   #creating a dataframe
names(df2) <- names(df)     #changing the column header names as this is a requirement for append

df <- rbind(df, df2)    #appending

df2这应该可以,除非我遗漏了什么:

df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789))

df如果适用,请提供副本,而不是发布答案。或者这一个或这一个或这一个或这一个,上述代码可以同时馈送多个df/tibble,而无需使用do.call循环。如下所示,数据帧之间的名称需要保持不变,以便对齐。
df2 <- data.frame(x2, y2)   #creating a dataframe
names(df2) <- names(df)     #changing the column header names as this is a requirement for append

df <- rbind(df, df2)    #appending
df <- data.frame("x" = c(1, 2, 3, 4, 5), "y" = c(0.255, 0.236, 0.587, 0.369, 0.789))
x <- c(6, 7, 8, 9, 10)
y <- c(0.236, 0.963, 0.356, 0.489, 0.333)
df2 <- bind_cols(list(x = x, y = y))
df3 <- bind_rows(list(df, df2))