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

Java 8 + Maven Javadoc plugin: Error fetching URL -

android - How to delete or change the searchview icon inside the SearchView actionBar? -

c++ - Msgpack packing bools bug -