0

My data has a median of 60. I'd like to create a dummy variable where 1 = >60 and 0 = <60.

E Bat
  • 11
  • 1

1 Answers1

2

You can use ifelse function.

a = 1:100

median = 60

ifelse(a >= median, 1, 0)

If you use data frame for this problem use dplyr(0.5.0) is more efficient.

a = data.frame(col1 = 1:100)



a %>% mutate(dummy = case_when(.$col1 >= 60 ~ 1,
                               .$col1 < 60 ~ 0))
golden_truth
  • 161
  • 7