My data looks like this:
Year Categories January February March April May June July August September October November December 1 1990 A 4564.0 465465.0 12 468 4884.0 12788.00 4218.00 -58445.86 -90643.00 -122840.1 -155037.29 -187234.4286 2 1990 B 6487.0 421214.0 878 2112 421283.0 56456.00 54654.00 515.00 212.00 515.0 212.00 515.0000 3 1990 C 42862.0 512.0 484 48 515.0 212.00 515.00 137858.33 48.00 137858.3 48.00 465.0000 4 1990 D 15.0 -169222.7 90 456 137858.3 48.00 465.00 135673.83 778.00 135673.8 778.00 12.0000 5 1990 E 19164.0 -401699.2 -304 246 135673.8 778.00 12.00 133489.33 57.00 133489.3 57.00 478.0000 6 1991 A 21436.8 -634175.7 -698 36 133489.3 57.00 478.00 131304.83 3.00 131304.8 3.00 331.3333 7 1991 B 23709.6 -866652.2 -1092 -174 131304.8 3.00 -8210.60 129120.33 30425.33 129120.3 -11463.57 337.8333 11 1992 A 32800.8 -1796558.2 -2668 -1014 122566.8 -27597.89 -29087.86 292051.00 82253.33 331147.5 -12728.17 363.8333 12 1992 B 35073.6 -2029034.7 -3062 -1224 120382.3 -32976.00 -34307.17 321333.47 95210.33 367329.4 -14420.56 370.3333 13 1992 C 37346.4 -2261511.2 -3456 -1434 118197.8 -38354.11 -39526.49 350615.94 108167.33 403511.2 -16112.96 376.8333
I would like to manipulate this data frame using tidyverse as follows:
First, there are no equal number of categories per year. All other categories should appear even if other years do not have specific categories. Because as you see for 90s there are 5 categories but for 91s there are only 2 categories.
In this, the data for months should be seen side by side instead of being seen line by line. So in the following way; Jan 90, Feb 90, ..., Dec 90, Jan 91, Feb 91, ...., Dec 91, Jan 92, ..., Dec 92 (These will appear as column names).
I want to see it this way in a column. Years should be deleted and only the unique categories should be displayed in the far left column (under Categories). After that if a category do not specific to a month of year which means there is no data for this month, there can be "0" for this month's below.
I would like to use tidyverse in R for this but I could not write it as code if you help me would be happy.
This is the expected version of the data but as I said the months should place side by side:
Categories Jan.90 Feb.90 Mar.90 Apr.90 May.90 June.90 July.90 Aug.90 Sep.90 Oct.90 Nov.90 Dec.90 Jan.91 Feb.91 Mar.91 1 A 4564 465465.0 12 468 4884.0 12788 4218 -58445.86 -90643 -122840.1 -155037.3 -187234.4 21436.8 -634175.7 -698 2 B 6487 421214.0 878 2112 421283.0 56456 54654 515.00 212 515.0 212.0 515.0 23709.6 -866652.2 -1092 3 C 42862 512.0 484 48 515.0 212 515 137858.33 48 137858.3 48.0 465.0 0.0 0.0 0 4 D 15 -169222.7 90 456 137858.3 48 465 135673.83 778 135673.8 778.0 12.0 0.0 0.0 0 5 E 19164 -401699.2 -304 246 135673.8 778 12 133489.33 57 133489.3 57.0 478.0 0.0 0.0 0 Apr.91 May.91 June.91 July.91 Aug.91 Sep.91 Oct.91 Nov.91 Dec.91 Jan.92 Feb.92 Mar.92 Apr.92 May.92 June.92 July.92 1 36 133489.3 57 478.0 131304.8 3.00 131304.8 3.00 331.3333 32800.8 -1796558 -2668 -1014 122566.8 -27597.89 -29087.86 2 -174 131304.8 3 -8210.6 129120.3 30425.33 129120.3 -11463.57 337.8333 35073.6 -2029035 -3062 -1224 120382.3 -32976.00 -34307.17 3 0 0.0 0 0.0 0.0 0.00 0.0 0.00 0.0000 37346.4 -2261511 -3456 -1434 118197.8 -38354.11 -39526.49 4 0 0.0 0 0.0 0.0 0.00 0.0 0.00 0.0000 0.0 0 0 0 0.0 0.00 0.00 5 0 0.0 0 0.0 0.0 0.00 0.0 0.00 0.0000 0.0 0 0 0 0.0 0.00 0.00 Aug.92 Sep.92 Oct.92 Nov.92 Dec.92 1 292051.0 82253.33 331147.5 -12728.17 363.8333 2 321333.5 95210.33 367329.4 -14420.56 370.3333 3 350615.9 108167.33 403511.2 -16112.96 376.8333 4 0.0 0.00 0.0 0.00 0.0000 5 0.0 0.00 0.0 0.00 0.0000