I am trying to replace column a1
of dataframe df1
by value b1
of dataframe df1
, if a1
matches. Please help me achieve this using basic R
functions
df1 <- data.frame(a1 = c("b2","c2","abc2"),b1 = c("bb2","cc2","d2"))
df2 <- data.frame(d1 = c("sale","sale2","sale3"),a1 = c("b2","c2","d2"))
> df2
a1 b1
1 sale b2
2 sale2 c2
3 sale3 d2
Expected output:
a1 b1
1 sale bb2
2 sale2 cc2
3 sale3 d2