title: How make a dataframe wider with new column names?
body: <p>I have the following dataset:</p>
  <pre><code>structure(list(year = c(2018, 2018, 2018, 2018, 2018, 2019, 2019, 
  2019, 2019, 2019, 2020, 2020, 2020, 2020, 2020, 2021, 2021, 2021, 
  2021, 2021), TOTS = c(22653.66, 3776.36, 786769.68, 66467.18, 
  199209.4, 11775.4230769231, 15522.0384615385, 730920.557692308, 
  120094.576923077, 130204.961538462, 17893.6923076923, 24584.9807692308, 
  817194.788461538, 72970.9807692308, 108324.673076923, 60074.1424882649, 
  15968.8804545455, 761367.376818182, 60402.795, 90225.7270337195
  ), TOTL = c(82043.56, 22908.66, 135925.42, 50448.36, 762679.18, 
  83680.1538461538, 35655.2115384615, 95892.4807692308, 57961.5, 
  726726.423076923, 162654.5, 41344.6153846154, 110685.038461538, 
  40149.4615384615, 664171.403846154, 382768.048313859, 66280.6981818182, 
  102604.390454545, 55316.4409090909, 459641.12922295), kind = c(&quot;Audi&quot;, 
  &quot;BMW&quot;, &quot;Suzuki&quot;, &quot;MB&quot;, &quot;Honda&quot;, &quot;Audi&quot;, &quot;BMW&quot;, &quot;Suzuki&quot;, &quot;MB&quot;, 
  &quot;Honda&quot;, &quot;Audi&quot;, &quot;BMW&quot;, &quot;Suzuki&quot;, &quot;MB&quot;, &quot;Honda&quot;, &quot;Audi&quot;, &quot;BMW&quot;, 
  &quot;Suzuki&quot;, &quot;MB&quot;, &quot;Honda&quot;)), row.names = c(NA, -20L), groups = structure(list(
      year = c(2018, 2019, 2020, 2021), .rows = structure(list(
          1:5, 6:10, 11:15, 16:20), ptype = integer(0), class = c(&quot;vctrs_list_of&quot;, 
      &quot;vctrs_vctr&quot;, &quot;list&quot;))), row.names = c(NA, 4L), class = c(&quot;tbl_df&quot;, 
  &quot;tbl&quot;, &quot;data.frame&quot;), .drop = TRUE), class = c(&quot;grouped_df&quot;, 
  &quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;))
  </code></pre>
  <p>Could you help to transform the data, so that it will have 4 rows (by year), and TOTS and TOTL are separated by groups i.e. TOTS_AUDI,TOTS_BMW,TOTS_SUZUKI ...</p>
  <p>I tried <code>dcast(test,day + TOTL + TOTS ~ kind, fun.aggregate = sum)</code>, however it does not work as characters are on the left and on the right of <code>~</code></p>