Merging two datasets

Dear all,

I am sure this must have been asked before but I cannot seem to find it...

So basically i have this:

Dataset 1:

Player Age
Player 1 32
Player 2 45
Player 3 18

Dataset 2:
Player 1 Player 2 Player 3
BMI 23 34 24

My final dataset should look like this:

Player Age BMI
Player 1 32 23
Player 2 45 34
Player 3 18 24

I tried different variations with rbind/cbind but I dont get it why it is not working...

Can anyone help me?:slight_smile: :slight_smile:

Thank you!!!

Hello,

Depending on how you want to specify it you can do it like the below. Let me know if this solves your problem. I simply went for a transpose with a cbind.



df <- data.frame(
      Player = c(1, 2, 3),
         Age = c(3, 45, 18)
)

BMI <- data.frame(
  Player_1 = 23,
  Player_2 = 34,
  Player_3 = 24
)

df2 <- cbind(df, BMI = t(BMI)) #you can do t(BMI) but then the name in the data.frame will be the same as the command. 

df2
#>          Player Age BMI
#> Player_1      1   3  23
#> Player_2      2  45  34
#> Player_3      3  18  24

Created on 2020-12-11 by the reprex package (v0.3.0)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Thank you so much !!! It is working! This was driving me crazy!!

Have a fantastic weekend :slight_smile: :slight_smile: :slight_smile:

1 Like