Hi,
I have this simple data file:
data.frame(stringsAsFactors=FALSE,
Unique.respondent.number = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
comment = c("I have seen many various charges in my life,
but I don’t like your saving rates",
"I like R Studio", "No comment",
"Main benefit is having low charges",
NA,
"Charge could be an issue",
"Issues with saving rates", "Good saving rates",
"Many benefits like reasonable charges", "N/A", "-",
"Nothing")
)
Now, I would like to recode all invalid or blank responses into a new variable called "Blank".
I can recode blank fields and single/double characters using these:
source$Blank <- ifelse(is.na(source$comment), 1, ifelse(str_length(source$comment)<3, 1, 0))
All fine but now, rather than guessing what other invalid responses could be ("No clue", "Nothing to say", "Don't know", "?", No comment"), I would like to use an external source to let R know that if "comment" equals any of the "No comment" values from the list, "Blank" should be recoded into 1.
Also, I know some respondents leave repetitive characters if have nothing to comment such as "zzzzz", "xxxx". Is any way of recoding "Blank" into 1 if a "comment" contains this repetitive string type?