How to use group by and breakdown the information into the categories.

Hi guys,
I am trying to organize a dataset regarding trade. I have the following columns: ReporterName, TradeFlowCode, Year, Category, PartnerName, TradeValue. I would like to reorganize this data so I can get something that resembles the following pivot table:

I know how to group and summarise the data by a single value - country or category. So I can get the information regardin the summarized value of trade with a given region/country or a category. However, I have no idea, how to first group by PartnerName(country or region) and then to have a category breakdown of different commodities traded with that Country or Region (as shown above in the Excel pivot table).
Thanks in advance for any ideas!

Can you supply some sample data?

See FAQ: How to do a minimal reproducible example ( reprex ) for beginners or a handy way to supply sample data is to use the dput() function. See ?dput. If you have a very large data set then something like head(dput(myfile), 100) will likely supply enough data for us to work with.

I'm sorry for not sampling any data. I already solved the problem. Thank you !

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.