I want to be able to see how many times a value has already been listed in the dataset. Thank you!!
test = c("a", "a", "b", "b", "a", "c")
I want to be able to return new_variable = c(1, 2, 1, 2, 3, 1)
based on the information above
I want to be able to see how many times a value has already been listed in the dataset. Thank you!!
test = c("a", "a", "b", "b", "a", "c")
I want to be able to return new_variable = c(1, 2, 1, 2, 3, 1)
based on the information above
Using 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