Code:
library(tidyr)
library(tibble)
df <- data_frame(animal = c("cat", "dog"), toy = c("ball", "stick"), total = c(5, 6))
df
Output:
# A tibble: 2 x 3
animal toy total
<chr> <chr> <dbl>
1 cat ball 5
2 dog stick 6
Code:
uncount(df, total)
Output:
# A tibble: 11 x 2
animal toy
<chr> <chr>
1 cat ball
2 cat ball
3 cat ball
4 cat ball
5 cat ball
6 dog stick
7 dog stick
8 dog stick
9 dog stick
10 dog stick
11 dog stick