ifelser is an R package created to make nested ifelse statements easier and in modern R way to write code.
A simple vectorized ifelse statement can be done like this with ifelser
library(ifelser) x <- 1:10 test_if(x > 5) %>% if_true(1) %>% if_false(0)
Sometimes you want to nest statments. This can be done using the following commands:
test_if(x>5) %>% if_true(1) %>% if_false() %>% test_if(x<2) %>% if_true(5) %>% if_false(0)
If you ommit if_false
or if_true
arguments, ifelser
will wait for another call for test_if
, meaning that you want to nest an ifelse statement. This can be done how many times you want.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.