I have a dataframe of anonymized data, like this:
31 32 36 NA
31 32 34 NA
31 32 NA NA
32 33 NA NA
And I have a "dictionary" that maps each anonymized value to an individual's ID, like this:
ID Number
Male1 31
Male2 32
Female1 33
Female2 34
Female3 36
I want to replace all of the values in the first dataframe with the corresponding ID, as stored in the second dataframe, like this:
Male1 Male2 Female3 NA
Male1 Male2 Female2 NA
Male1 Male2 NA NA
Male2 Female1 NA NA
I've tried using ifelse
statements and replace
, but nothing has worked so far. I tried:
Test2 <- ifelse(Dataframe1 == Dataframe2$Number, Dataframe2$ID, Dataframe2$ID)
But this only replaced instances where the same value was in the same place in the dataframe, so I got:
Male1 32 36 NA
31 32 34 NA
31 32 NA NA
32 33 NA NA
I'm pretty much completely stuck. I would really appreciate any help, and especially explanations of solutions- I'm a graduate student who's really new to working with r.
Thanks so much!