jeudi 14 juin 2018

Regex in if else statement in R

I have a rather simple question. I am trying to get the if else statement below to work.

It is supposed to assign '1' if the if statement is met, 0 otherwise. My problem is that I cannot get the regex in the if statement to work ('\w*|\W*). It is supposed to specify the condition that the string either is "Registration Required" or Registration required followed by any character. I cannot specify the exact cases, because following the "Registration required" (in the cases where something follows), it will usually be a date (varying for each observation) and a few words.

Registration_cleaned <- c()

for (i in 1:length(Registration)) {
  if (Registration[i] == ' Registration Required\\w*|\\W*') {
    Meta_Registration_cleaned <- 1
  } else {
    Meta_Registration_cleaned <- 0 
  }

 Registration_cleaned <- c(Registration_cleaned, Meta_Registration_cleaned)

}

Aucun commentaire:

Enregistrer un commentaire