I have a time series with daily precipitation data between 1961 and 2017, as shown below. I need to bundle this data by month over the years. I was able to transpose the month column of the data frame and fill it with the values in the "prec" column, using the dcast
function, for example the question contained in 1 .
ID dia mes ano prec
1 21 ago 1961 NA
2 22 ago 1961 0.00
3 23 ago 1961 1.00
4 24 ago 1961 0.00
5 25 ago 1961 0.00
6 26 ago 1961 0.00
7 27 ago 1961 0.00
8 28 ago 1961 0.00
9 29 ago 1961 0.00
10 30 ago 1961 NA
11 31 ago 1961 0.00
12 1 set 1961 0.00
13 2 set 1961 0.00
14 3 set 1961 0.00
15 4 set 1961 0.00
16 5 set 1961 0.00
17 6 set 1961 0.00
18 7 set 1961 0.00
19 8 set 1961 NA
20 9 set 1961 0.00
21 10 set 1961 0.00
22 11 set 1961 0.00
23 12 set 1961 0.00
24 13 set 1961 0.00
25 14 set 1961 0.00
26 15 set 1961 0.00
27 16 set 1961 0.00
28 17 set 1961 0.00
29 18 set 1961 0.00
30 19 set 1961 0.00
31 20 set 1961 0.00
32 21 set 1961 0.00
33 22 set 1961 0.00
34 23 set 1961 0.00
35 24 set 1961 0.00
36 25 set 1961 0.00
37 26 set 1961 0.00
38 27 set 1961 0.00
39 28 set 1961 0.00
40 29 set 1961 0.00
41 30 set 1961 0.00
However, the resulting data frame does not display the consecutive values of precipitation for each month, but rather blocks of values as a function of the table ID, as schematically represented below.
ID jan fev ... ago set ... dez
1 Na
2 0
3 1
. .
. .
. .
11 0
12 0
. .
. .
. .
41 0
42 0
How do I resolve this problem?