I have this vector of strings (strings_input) which I want to be a vector of numbers like the expected_output.
strings_input <- c("a", "a", "b", "b", "b", "c", "c", "a", "b", "b")
some function:
expected_output <- c(1, 1, 2, 2, 2, 3, 3, 4, 5, 5)
I have this vector of strings (strings_input) which I want to be a vector of numbers like the expected_output.
strings_input <- c("a", "a", "b", "b", "b", "c", "c", "a", "b", "b")
some function:
expected_output <- c(1, 1, 2, 2, 2, 3, 3, 4, 5, 5)
Copyright © 2021 Jogjafile Inc.
Use
data.table::rleid:Or in base R:
There is also a
dplyr'sconsecutive_id: