0

I want to recode a variable called 'booktitle', based on the presence or absence of certain strings. If the field is blank or contains specific 'negative' words, I want to code my new variable "No". If none of the negative words are present, I want to code my new variable "Yes".

I tried the following:

newvar <- ifelse(
  booktitle==c("","n/a","na","none","do not","not really","not committed",
               "not a fan","NOne","not fan"),
  "No",
  "Yes"
)

and got an error message:

Error in $<-.data.frame(*tmp*, "myDF", value = logical(0)) : replacement has 0 rows, data has 411.

I also tried it using '|' instead of commas to represent 'or'.

thelatemail
  • 91,185
  • 12
  • 128
  • 188
user3614783
  • 821
  • 6
  • 12
  • 20

0 Answers0