samedi 27 novembre 2021

IF THEN STATEMENT IN R - REPLACING BASED ON VALUE

I have a very large file where I have merged two customer databases. The key is the ID. Where the customer name did not match it shows an NA. I need to accomplish a simple if/then statement where if there is "NA" in column NAME_1 the DESIRED OUTCOME NAME is what is in NAME_2, else use what is in NAME_1

I attempted the following code but get errors

df <- df %>% if (df$NAME_1 == "NA") rename(df$NAME_1 == df$NAME_2)

enter image description here

Aucun commentaire:

Enregistrer un commentaire