x <- rep(c("A","B","C"),times=c(6,8,3))
"A" "A" "A" "A" "A" "A" "B" "B" "B" "B" "B" "B" "B" "B" "C" "C" "C"
I'm struggling to create a vector that corresponds to each letter being divided into exactly 3 bins:
(A A A A A A B B B B B B B B C C C)
x_bin = 1 1 2 2 3 3 1 1 1 2 2 2 3 3 1 2 3
In this example, I can divide A
into 3 bins by combining every 2 values. I can divide B
into 3 bins by combining 3, 3 and 2 values. And I can only divide C
into 3 bins by combining 1 value.
Is there a function that allows me to do this? I tried with cut
and dplyr
but cut
only works with numeric data and it doesn't cut the way I want.
sort
is a good idea, cheers! – Fastback