0

I have a dataframe containg two columns, with country's names, and a value. I would now want that e.g. country "Italy" and all others, are columns, and than the values to be shown for each year under the country they belong to.

I want the dataframe to look like this:

Italy Spain
2020 1246 64829
2021 230 11320

Instead, it looks like this:

Country Value
ITA-20 Italy 1246
ITA-21 Italy 230
SPA-20 Spain 64829
SPA-21 Spain 11320

So, basically I want that instead of every country plus year to be only year written, and than the countries are written in the columns. I would be very happy if anyone could help me. Thank you a lot in advance! :)

  • try `tidyr::pivot_wider(df, names_from = Country, values_from = Value)` – AndS. Oct 25 '22 at 19:47
  • @AndS. thank you. Now the countries names are shown as I wanted, but the values are now in a row, and for each country as a combine function, that means I can not see them to which year the value belongs to. Do you have any idea for that? – user20332904 Oct 25 '22 at 19:54

0 Answers0