I have the following two data frames:
d <- data.frame(c1 = c("A","A","B","C","A","C","D","D"))
map <- data.frame(c1 = c("A","B","C","D"), c2 = c(12,14,16,25))
How can I add another column called “match” to data frame d that contains corresponding values found in data frame map? So data frame d should look like:
A 12
A 12
B 14
C 16
A 12
C 16
D 25
D 25
Many thanks in advance!
Using the function called
match:And because of the way these levels are specified, you could also do:
But this only works if each row in
matchexactly matches the levels of thec1factor in order.