2

I expect the below code

library(dplyr)
library(broom)

d <- data.frame(a = 1:3, b = 8:10)

d %>% inflate(x = c("apple", "orange"), y = c("car", "boat"))

to give me a 12 x 4 data frame that looks like this:

## 1 apple boat 1 8
## 2 apple boat 2 9
## 3 apple boat 3 10
## 4 apple car 1 8
## 5 apple car 2 9
## 6 apple car 3 10
## 7 orange boat 1 8
## 8 orange boat 2 9
## 9 orange boat 3 10
## 10 orange car 1 8
## 11 orange car 2 9
## 12 orange car 3 10

but instead it gives me this:

# A tibble: 4 x 2
# Groups:   x, y [4]
       x     y
   <chr> <chr>
1  apple  boat
2  apple   car
3 orange  boat
4 orange   car

It seems that d is ignored. What's going on?

alistaire
  • 42,459
  • 4
  • 77
  • 117

1 Answers1

0

Try tidyr::crossing:

library(tidyr)

d <- data.frame(a = 1:3, 
                b = 8:10)

d %>% crossing(x = c("apple", "orange"), 
               y = c("car", "boat"))
#>    a  b      x    y
#> 1  1  8  apple boat
#> 2  1  8  apple  car
#> 3  1  8 orange boat
#> 4  1  8 orange  car
#> 5  2  9  apple boat
#> 6  2  9  apple  car
#> 7  2  9 orange boat
#> 8  2  9 orange  car
#> 9  3 10  apple boat
#> 10 3 10  apple  car
#> 11 3 10 orange boat
#> 12 3 10 orange  car
alistaire
  • 42,459
  • 4
  • 77
  • 117