创建一个列,这样 - 如果 `x` 位于前 150 名,则其值为 "Good"。否则它的值为 "Bad"

Create a column such that - If `x` lies in top 150, its value is "Good". Else its value is "Bad"

如何在 tbl 中创建二进制列 performance 以便 -

如果 x 位于前 150 名(我们的 243 名),则性能值为“好”

否则,性能值为“差”

tbl <- tibble(x = runif(n = 243, min = 0, max = 1))

如果我理解正确你的问题,这应该有效:

tbl %>%
    arrange(desc(x)) %>%
    mutate(performance = case_when(
            row_number() < 150 ~ "Good",
            TRUE ~ "Bad"))