rif-statementcase

How do I check one column in R for a specific word and overwrite or return that word in another column?


Using R, I want to check the ManufShortName column and if there is the word 'BLANK', then I want to return the word 'BLANK' in another column named AnalysisNotesCode in the same row.

If there is a word currently written in the AnalysisNotesCode column, I want to overwrite it with 'BLANK'. How do I do this? Thank you!


Solution

  • Basically the same as davearmstrong's comment but using tidyverse.

    library(dplyr)
    
    mydata <- mydata |>
     mutate(AnalysisNotesCode = if_else(ManufShortName == "BLANK", "BLANK", AnalysisNotesCode)