0

I am having trouble trying to get a new dataframe that consists of all the combinations of two columns in a dataframe. Then do a Pivot_wide to represent the data in a specific way. See example pictures of before and after. The before picture is the data injested, and the after picture is how the dataframe should look afterwards. Before After

r2evans
  • 141,215
  • 6
  • 77
  • 149
white2tj
  • 1
  • 3
  • Please share copy/pasteable sample data in valid R syntax, not pictures of spreadsheets. If you have the data in R, you can generate copy/pasteable R syntax with `dput()`, e.g., `dput(your_sample_data)` or a small subset or larger data, `dput(your_data[1:4, ])` for the first 4 rows. – Gregor Thomas Jun 01 '22 at 15:10
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jun 01 '22 at 15:11
  • 1
    Also please show your attempt--what did you try and where did you get stuck? [We have a FAQ about generating all combinations](https://stackoverflow.com/questions/11388359/unique-combination-of-all-elements-from-two-or-more-vectors), have you tried some of the ideas there? Maybe `expand.grid` or `tidyr::complete`? – Gregor Thomas Jun 01 '22 at 15:12
  • `expand.grid(column1, column2)` will do the job – Yacine Hajji Jun 01 '22 at 15:23
  • ... or is it that you are reshaping the data? It looks as if one of your original columns might be used to feed the column names and therefore reshape the data. Are columns `$A:$E` of your first worksheet all there is to the data? – r2evans Jun 01 '22 at 21:01

0 Answers0