[英]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.