0

I am new to R and I am having some trouble. I am trying to replace some specific values of a data frame according to different values from another df. For example:

I have this two dataframes:

a <- data.frame(c('a','b','c','d'), c('g','e','p','d'))

1  a  g
2  b  e
3  c  p
4  d  d

b <- data.frame(c('a','c'))

1  a
2  c

I want to find out which items that are on df a are also on df b and assign the value of the next column, in this case 'g' and 'p'. I tried with the match function but it has a problem if there are many items with the same name that need to be changed. I would really want an option to do this without checking 1 by 1 with a loop.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • `a$C2[match(b$C1, a$C1)]` where `C1` and `C2` are your column names for first and second columns respectively. – Ronak Shah Jul 21 '17 at 02:43
  • Possible duplicate of [Match values in data frame with values in another data frame and replace former with a corresponding pattern from the other data frame](https://stackoverflow.com/questions/11530184/match-values-in-data-frame-with-values-in-another-data-frame-and-replace-former) – Ronak Shah Jul 21 '17 at 02:47

0 Answers0