Home > Blockchain >  Create dummy variable using tidyverse?
Create dummy variable using tidyverse?

Time:01-24

How would you create a dummy variable using tidyverse? I can do it in the base R syntax by using the ifelse function, but I'm stumped by how to do it using a tidyverse function.

CodePudding user response:

If you could present your problem in detail and show the structure of your data (i.e. using dput(head(data))), others can help you in a better way. As I understand your question, you can use tidyverse verbs as follow:

data %>% mutate(new_var = if_else(condition, 1, 0))
  •  Tags:  
  • Related