-6

I am doing an assignment with the built-in "SWISS" dataset, and where the value is greater than 50 I need to create a binary variable taking 1

I have a feeling that I might have to use the subset command, but I am lost as how to implement it.

Hack-R
  • 22,422
  • 14
  • 75
  • 131

1 Answers1

0

using dplyr

swiss %>% 
   mutate(aggGreaterThan50 = (Agriculture > 50) * 1)
Angel Eyes
  • 302
  • 3
  • 8
  • 2
    I would argue that `as.numeric(Agriculture > 50)` is stylistically preferable (I find the `*1/+0` tricks for converting to numeric to be a little *too* tricky/terse ... – Ben Bolker Oct 30 '16 at 23:34