拜托,我有这么宽的数据,我想把它透视成长数据。
Country MDA BI MDA Last Year BI Last Year Month
Netherland 230 280 234 789 June
Scotland 100 340 456 234 June
UK 100 100 768 567 June
USA 200 780 765 123 June
Ireland 100 890 675 987 June
Nigeria 500 560 234 876 June
我使用了pivot_longer()
函数,但似乎没有正确使用它。我希望输出为以下格式。
Country Cur_Year Prod_Cat_new Prev_Year Prod_cat_old Month
Netherland 230 MDA 234 MDA Last Year June
Scotland 100 MDA 456 MDA Last Year June
UK 100 MDA 768 MDA Last Year June
USA 200 MDA 765 MDA Last Year June
Ireland 100 MDA 675 MDA Last Year June
Nigeria 500 MDA 234 MDA Last Year June
Netherland 280 BI 789 BI Last Year June
Scotland 340 BI 234 BI Last Year June
UK 100 BI 567 BI Last Year June
USA 780 BI 123 BI Last Year June
Ireland 890 BI 987 BI Last Year June
Nigeria 560 BI 876 BI Last Year June
1条答案
按热度按时间q1qsirdb1#
使用
pivot_longer
将其整形为长型,并从Prod_cat
列创建这些Prod_cat_new
、Prod_cat_old
数据