mardi 10 septembre 2019

Create New Variable Using Ifelse Contains Text

I want to create a new variable that indicates whether someone's diagnosis contained the words "Adolescent idiopathic scoliosis". There is additional text in the diagnoses as well. I want to create a variable that is indicates whether someone has this diagnosis or not.

I originally wanted to do this using mutate in dplyr. Then I also tried grepl.

grepl

Scoliosis$Adolesc.Idiopathic.Scoliosis <- 
  ifelse(grepl("Adoloescent idiopathic scoliosis",
                   Scoliosis$Encounter.Primary.Visit.Diagnosis.Name),
                                           "Adolescent Idiopathic Scoliosis", "Different Diagnosis")

Also, could something like this work in dplyr? I didn't finish the code because every way I tried it failed:

Scoliosis <- Scoliosis %>% 
  mutate(Adolesc.Idiopathic.Scoliosis = ifelse(Encounter.Primary.Visit.Diagnosis.Name %in% 

This is the table I get for the code:

 table(Scoliosis$Adolesc.Idiopathic.Scoliosis)

Different Diagnosis 75311

There should be some that come up with the result "Adolescent Idiopathic Scoliosis"

Aucun commentaire:

Enregistrer un commentaire