I have two dataframes containing information as follows:
> df1:
X1 X2
Adele Soul
Cher Pop
Sting Rock
Beyonce R&B
and
> df2:
name completeName
B Beyonce
A Adele
S Sting
M Madonna
E Elvis
C Cher
D Duffy
And I am trying to match them to create new column in df1
to make it look like this:
> df1:
X1 X2 Name
Adele Soul A
Cher Pop C
Sting Rock S
Beyonce R&B B
I have tried with df1 <- df1[order(match(df2$name, df1)), 1]
but somehow I cannot get the Name
column in the same order as df1$X1
.
Any ideas? Preferably in Base R
.
I have been applying ideas from other similar question but it doesn't seem to work for me.