So, I have a dataset with 2 columns X and Y. Y is an integer between 0 and 5. I need to change the level of the detail of the dataset.
I want to copy the rows the number of times Y indicates As an example
X | Y
______
a | 1
b | 0
c | 2
Becomes
X |
___
a |
c |
c |
a remains once, b disappears and c appears now twice. I do not need to keep the Y number, except in the number of rows of X.
My first thought was to do
df4 <- df %>% filter (Y=4)
df4 <- rbind(df4, df4, df4, df4) %>% select (-Y)
but that all seems ugly, and it is not generalizable to Y =20 as an example.
Thank you!