powered by
ifelse.() utilizes data.table::fifelse() in the background, but automatically converts NAs to their proper type.
ifelse.()
data.table::fifelse()
ifelse.(conditions, true, false, na = NA)
Conditions to test on
Values to return if conditions evaluate to TRUE
Values to return if conditions evaluate to FALSE
Value to return if an element of test is NA.
# NOT RUN { x <- 1:5 ifelse.(x > 2, 2, 0) # Can also be used inside of mutate.() test_df <- data.table(x = x) test_df %>% mutate.(new_col = ifelse.(x > 2, 2, 0)) # }
Run the code above in your browser using DataLab