powered by
Fast version of base::ifelse().
base::ifelse()
ifelse.(conditions, true, false, na = NA)
Conditions to test on
Values to return if conditions evaluate to TRUE
TRUE
Values to return if conditions evaluate to FALSE
FALSE
Value to return if an element of test is NA
NA
x <- 1:5 ifelse(x < 3, 1, 0) # Can also be used inside of mutate() df <- data.table(x = x) df %>% mutate(new_col = ifelse(x < 3, 1, 0))
Run the code above in your browser using DataLab