rstudio - Multiple conditions for ifelse statements in R -
this question has answer here:
responses$status
has multiple statuses: invited, attended, registered, downloaded, sent, added
i tried create new binary column using code:
responses$hasresponded <- ifelse(responses$status == c("responded", "attended", "downloaded", "contacted", "requested"),1,0)
this code runs, not doing want do. is, code 1 of these statuses ("responded", "attended", "downloaded", "contacted", "requested")
, , 0 rest.
%in%
friend.
splitting bit readability:
okresp <- c("responded", "attended", "downloaded", "contacted", "requested") responses$hasresponded <- as.numeric(responses$status %in% okresp)
or
responses <- transform(responses, hasreponded = status %in% okresp)
Comments
Post a Comment