Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replacing some data from a column with another column data only where a certain condition is met in R (dplyr)

I have an extensive data frame with 30+ columns and 10000+ rows. Today I want to focus in two columns: languages and languages2:

languages             languages2

Spanish                  NA
Spanish                  NA
Other (specify)        French
Other (specify)        German
Other (specify)        Russian
English                  NA
Other (specify)        Portuguese
English                  NA
(...)

This is what I need:

languages

Spanish
Spanish
French
German
Russian
English
Portuguese
English
(...)

I am looking for an answer using mutate function from dplyr

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

data %>% 
  mutate(languages=if_else(languages=="Other (specify)", languages2, languages)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading