I have a dataframe with several columns of which one with frequencies (see code below). I would like to insert rows depending on the frequencies mentioned in that column.
I have tried code like this:
df %<>% rowwise() %>%
slice(rep(1:n(), .$lengte))
and variations on this, but non seem to work exactly the way I want
# sample of original dataframe
df <- data.frame(x = c(1,1,2,2), y = c(0,1,0,1), frequency = c(2,3,4,5))
The expected output would be:
dfout <- data.frame(x = c(1,1,1,1,1,2,2,2,2,2,2,2,2,2), y = c(0,0,1,1,1,0,0,0,0,1,1,1,1,1))