简体   繁体   English

将一个数据帧的列添加到另一个类似数据帧的列

[英]Add a column of one data frame to a column of another similar data frame

I have 2 data.frames similar to this one below: 我有2个data.frames类似于下面这个:

df1
  x  y
1 1  6
2 2  7
3 3  8
4 4  9
5 5 10

df2
   x y
1  6 1
2  7 2
3  8 3
4  9 4
5 10 5

I want to add the column 'x' of the first data.frame to the column 'x' of the second data.frame (same operation for column 'y' also) to get a new data.frame like this: 我想将第一个data.frame的列'x'添加到第二个data.frame的列'x'(也是'y'列的相同操作)以获得一个新的data.frame,如下所示:

df
       x y
    1  7 7
    2  9 9
    3  11 11
    4  13 13
    5  15 15 

Say, I have more than 2 data.frames with more than 2 columns in each data.frame. 比如,我有超过2个data.frames,每个data.frame中有超过2列。 How can I do this? 我怎样才能做到这一点?

You just plus them together since they only contain numbers 你只需将它们加在一起,因为它们只包含数字

df1+df2

edit: for a lot of data.frames in a list, call that list x : 编辑:对于列表中的大量data.frames,调用该列表x

Reduce("+", x)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 R-如何将数据框的列添加为另一个数据框的列? - R - How to add column of data frame as column of another data frame? 如何对一个数据框中的列值求和并将结果添加为另一个数据框中的列? - How to sum values of column in one data frame and add results as a column in another data frame? 在 R 的 data.frame 中的另一列下方添加一列 - Add one column below another in a data.frame in R 根据另一个数据框将计算列添加到数据框 - Add a calculated column to data frame based on another data frame 使用另一个数据框中的循环计算将列添加到数据框 - Add column to data frame with loop calculation from another data frame 根据另一个数据框中的列在一个数据框中应用正则表达式 - apply regexp in one data frame based on the column in another data frame 将文本添加到data.frame的一列 - Add text to one column of data.frame 根据另一行中另一列的值将列添加到数据框 - Add column to data frame based on values of another column in another row 需要向数据框添加一列。 数据在另一个向量中,仅是一个原始DF列的子集,以供参考 - Need to add a column to a data frame. The data is in another vector and is only a subset of one original DF column for reference 根据一列中的相似值重塑data.frame - reshape a data.frame based on similar value in one column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM