How do I create a binary column performance
in tbl
such that -
If x
lies in top 150 (our of 243), value of performance is "Good"
Else, value of performance is "Bad"
tbl <- tibble(x = runif(n = 243, min = 0, max = 1))
CodePudding user response:
If i understand correctly your question this should work:
tbl %>%
arrange(desc(x)) %>%
mutate(performance = case_when(
row_number() < 150 ~ "Good",
TRUE ~ "Bad"))