Reputation: 1232
I am looking to create some logic that would look as such in SQL
CASE WHEN COLUMN IS NOT NULL THEN 1 ELSE 0 END
How would this look like within the mutate verb using dplyr?
I was thinking
mutate(Bucket = case_when(!is.na(COLUMN) ~ 1,0))
Would this work
Upvotes: 0
Views: 1109
Reputation: 521168
I would just use if_else
here:
mutate(Bucket = if_else(!is.na(COLUMN), 1, 0))
The case_when
function would be better suited to a SQL CASE
expression having more than one logical branch.
Upvotes: 3