Anupama Pasumarthy
Anupama Pasumarthy

Reputation: 1

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:

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:

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. How can I do this?

Upvotes: 0

Views: 61

Answers (1)

JeremyS
JeremyS

Reputation: 3525

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:

Reduce("+", x)

Upvotes: 2

Related Questions