2
I have a time series with daily precipitation data between 1961 and 2017, as an example below. I need to group these data by month over the years. I was able to transpose the "month" column of the data frame and fill in the values of the "Prec" column, using the function dcast
, like the question 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 present the consecutive precipitation values for each month, but rather blocks of values as a function of the table ID, as shown schematically below.
ID jan fev ... ago set ... dez
1 Na
2 0
3 1
. .
. .
. .
11 0
12 0
. .
. .
. .
41 0
42 0
How can I solve this problem?
The xtabs function worked in part because the lines containing NA have been deleted and I need them maintained. Is there any way to do that? I tried to follow the example of help, but it didn’t work either.
– Andreia Almeida
Actually, I noticed that the function xtabs gives me the frequency of measurements. Is that msm? While I need a function that transfers rain values to the columns, each column being a month of the year.
– Andreia Almeida