0

I have the following data frame:

data.frame(col_1 = c("a", "b", "c"),
           col_2 = c(1, 2, 3))

I would like to make all values from the col_1 have correpondences with all the values from col_2.

The expected result would be like this:

data.frame(col_1 = c("a", "a", "a", "b", "b", "b", "c", "c", "c"),
           col_2 = c(1, 2, 3, 1, 2, 3, 1, 2, 3))

I have tried with spread and reshape but it did not work.

Honorato
  • 111
  • 6
  • 1
    `do.call(expand.grid, your_data)` or `expand.grid(col_1 = your_data$col_1, col_2 = your_data$col_2)` in base R, or `tidyr::expand(your_data, col_1, col_2)` – Gregor Thomas Apr 05 '23 at 16:19

0 Answers0