我希望能够看到一个值已经在数据集中列出了多少次。谢谢!!
test = c("a", "a", "b", "b", "a", "c")
我希望能够根据上述信息返回new_variable = c(1, 2, 1, 2, 3, 1)
答案 0 :(得分:0)
使用tidyverse
library(tidyverse)
test = c("a", "a", "b", "b", "a", "c")
resulting_vector <- test %>% as_tibble() %>%
group_by(value) %>%
mutate(total = row_number()) %>%
pull(total)
resulting_vector