Search code examples
rdata-cleaning

Replacing 1 variable in 1 column with variables in aonther column


I have a database in which one column D2 is marked with 3 different variables NA, Year, Prefer Not To Answer. I want to replace the Year with the numeric answers in the second column D2_TEXT

I am using Rstudio and I have dplyr and tidyverse installed.

Database Example


Solution

  • your_data <- mutate(your_data, D2 = ifelse(D2 == 'Year', D2_TEXT, D2))
    

    Thank you Axeman