rstudio - Multiple conditions for ifelse statements in R -


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

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -