I have a DF1 with a column which has 20000 observations, it has 1214 unique values like 5,10,15,... 7480 and I have other DF2 with two columns of size 1214, the first one has the same values 5,10,15,... 7480 and the second one have names that correspond to each number in the fisrt column for example 5 correspond to DAVID, 10 correspond to XIMENA, etc. The question is How can I change the values of the DF1 by names correspondign to DF2 ? Thank you so much !

       ACTUAL STATUS
DF1:                    DF2:
COLUMN1                 COL1    COL2
 5                       5      DAVID
 5                       10     XIMENA
 5                       15     CARLOS
 10                      20     ROBERT
 10                      .        .
 10                      .        .
 15                      .        .
 15                      7480     RITA
 15                     
 .                     
 .                      
 .                      
 .  
 7480                    
 7480                  
       EXPECTED RESULT

DF1:                  

COLUMN1               

 DAVID                
 DAVID                
 DAVID                
 XIMENA               
 XIMENA               
 XIMENA               
 CARLOS               
 CARLOS               
 CARLOS                 
 .                     
 .                      
 .                      
 .  
 RITA                  
 RITA                  

1 Answers

0
nycrefugee On Best Solutions

you can use a simple merge and then de-select the index column. In this example I've piped together the functions using tidyverse so it's easy to use select to get rid of the index and rename to how you wish.

library(tidyverse)

DF1 %>%
  merge(DF2, by.x = "COLUMN1", by.y = "COL1", all.x = T) %>% 
  select(-COLUMN1) %>%
  rename(COLUMN1 = COL2)