[R] monthly sum
Rui Barradas
ruipbarradas at sapo.pt
Mon Mar 31 22:29:41 CEST 2014
One more thing, as.yearmon considers dates such as 1-Jan-61 to be of
year 2061 when they may be of year 1961. There's no problem with that if
the only use for them is in aggregate().
Rui Barradas
Em 31-03-2014 21:22, Rui Barradas escreveu:
> Hello,
>
> You have several columns of class "character" that must be converted to
> "numeric" before the code I previously posted can work:
>
> dat[,-1] <- lapply(dat[,-1], as.numeric)
>
> Then use aggregate().
>
> Rui Barradas
>
> Em 31-03-2014 20:24, eliza botto escreveu:
>> Dear Rui,
>>
>> I noticed that the previous data was not loading into my R. If it the
>> case with you, please use the following data.
>>
>> structure(list(Date = c("1-Jan-61", "2-Jan-61", "3-Jan-61", "4-Jan-61",
>> "5-Jan-61", "6-Jan-61", "7-Jan-61", "8-Jan-61", "9-Jan-61", "10-Jan-61",
>> "11-Jan-61", "12-Jan-61", "13-Jan-61", "14-Jan-61", "15-Jan-61",
>> "16-Jan-61", "17-Jan-61", "18-Jan-61", "19-Jan-61", "20-Jan-61"
>> ), A = c("0.00", "6.10", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00"), B = c(1.27, 9.144, 0.508,
>> 0, 0, 0, 0, 0, 1.27, 4.064, 1.016, 0, 0, 0, 0, 0, 0, 0, 0, 0),
>> C = c(8.128, 94.742, 1.27, 0, 0, 0, 0, 0, 0, 4.826, 0, 1.27,
>> 0, 0, 0, 0, 0, 0, 0, 0), D = c(NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), E = c(0.25,
>> 15.49, 0, 0, 0, 0, 0, 0, 0.25, 0.76, 0.76, 0, 0, 0, 0, 0,
>> 0, 0, 0, 0), F = c(NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_), G = c(0, 6.1, 0,
>> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), H = c(NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_), I = c(NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_), J = c("0.00", "4.32", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "5.33", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00"),
>> K = c("0.00", "10.67", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00"), L = c("0.00", "5.33",
>> "6.60", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "2.79",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00"), M = c(NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_), NA. = c(NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_), X0 = c(NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_), P = c(NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_), Q = c(NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_), R = c(NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_), S = c("0.00", "4.83", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.51", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00"),
>> T = c(NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_
>> ), U = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_)), .Names = c("Date", "A", "B",
>> "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "NA.",
>> "X0", "P", "Q", "R", "S", "T", "U"), row.names = c(NA, 20L), class =
>> "data.frame")
>>
>>
>> Thanks,
>>
>> Eliza
>>
>> > From: eliza_botto at hotmail.com
>> > To: ruipbarradas at sapo.pt; r-help at r-project.org
>> > Date: Mon, 31 Mar 2014 19:11:34 +0000
>> > Subject: Re: [R] monthly sum
>> >
>> > Dear Rui,
>> > Here is the complete data.
>> > > dput(dat)
>> > structure(list(Date = c("1-Jan-61", "2-Jan-61", "3-Jan-61",
>> "4-Jan-61", "5-Jan-61", "6-Jan-61", "7-Jan-61", "8-Jan-61", "9-Jan-61",
>> "10-Jan-61", "11-Jan-61", "12-Jan-61", "13-Jan-61", "14-Jan-61",
>> "15-Jan-61", "16-Jan-61", "17-Jan-61", "18-Jan-61", "19-Jan-61",
>> "20-Jan-61", "21-Jan-61", "22-Jan-61", "23-Jan-61", "24-Jan-61",
>> "25-Jan-61", "26-Jan-61", "27-Jan-61", "28-Jan-61", "29-Jan-61",
>> "30-Jan-61", "31-Jan-61", "1-Feb-61", "2-Feb-61", "3-Feb-61",
>> "4-Feb-61", "5-Feb-61", "6-Feb-61", "7-Feb-61", "8-Feb-61", "9-Feb-61",
>> "10-Feb-61", "11-Feb-61", "12-Feb-61", "13-Feb-61", "14-Feb-61",
>> "15-Feb-61", "16-Feb-61", "17-Feb-61", "18-Feb-61", "19-Feb-61",
>> "20-Feb-61", "21-Feb-61", "22-Feb-61", "23-Feb-61", "24-Feb-61",
>> "25-Feb-61", "26-Feb-61", "27-Feb-61", "28-Feb-61", "1-Mar-61",
>> "2-Mar-61", "3-Mar-61", "4-Mar-61", "5-Mar-61", "6-Mar-61", "7-Mar-61",
>> "8-Mar-61", "9-Mar-61", "10-Mar-61", "11-Mar-61", "12-Mar-61",
>> "13-Mar-61", "14-Mar-61", "15-Mar-61", "16-Mar-61", "17-Mar-61", "18-!
>> > Mar-61", "19-Mar-61", "20-Mar-61", "21-Mar-61", "22-Mar-61",
>> "23-Mar-61", "24-Mar-61", "25-Mar-61", "26-Mar-61", "27-Mar-61",
>> "28-Mar-61", "29-Mar-61", "30-Mar-61", "31-Mar-61", "1-Apr-61",
>> "2-Apr-61", "3-Apr-61", "4-Apr-61", "5-Apr-61", "6-Apr-61", "7-Apr-61",
>> "8-Apr-61", "9-Apr-61", "10-Apr-61"), A = c("0.00", "6.10", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "1.78", "12.95", "25.91", "0.00", "0.51", "34.04",
>> "3.30", "19.30", "0.76", "13.97", "3.81", "18.29", "9.14", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "6.86", "0.00", "6.86", "0.00", "0.00", "0.00", "1.52", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "5.84", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "9.65", "0.00", "0.00", "37.08", "0.00", "0.00", "0.00", "0.00",
>> "19.05", "0.00", "0!
>> > .00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "18.29",
>> > "12.45", "11.94", "0.00", "0.00", "0.00", "0.00", "9.40"), B =
>> c(1.27, 9.144, 0.508, 0, 0, 0, 0, 0, 1.27, 4.064, 1.016, 0, 0, 0, 0, 0,
>> 0, 0, 0, 0, 0, 0, 0, 2.032, 15.494, 36.576, 6.858, 1.778, 76.2, 13.97,
>> 32.512, 6.604, 32.258, 3.556, 15.24, 11.176, 2.794, 7.366, 0, 0, 0, 0,
>> 0, 0, 0, 0, 0, 4.826, 0.508, 5.588, 0, 0, 0, 0, 0.254, 0, 0, 0, 0, 0, 0,
>> 0, 0, 5.588, 0, 0, 0, 0, 4.064, 2.794, 2.54, 0, 0, 0, 9.906, 0, 0,
>> 30.734, 0, 0, 0, 0, 32.258, 5.08, 0, 0, 0, 0, 0, 0, 0, 2.54, 17.018,
>> 7.112, 11.43, 0, 2.54, 0, 0, 12.954), C = c(8.128, 94.742, 1.27, 0, 0,
>> 0, 0, 0, 0, 4.826, 0, 1.27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.556,
>> 1.016, 8.128, 0, 0.762, 62.738, 19.05, 32.512, 15.24, 33.02, 2.032,
>> 16.256, 2.54, 2.54, 5.842, 1.27, 0, 0, 0, 0, 0, 0, 0, 0, 6.858, 1.016,
>> 6.604, 0, 0, 0, 0, 1.524, 0, 0, 0, 0, 0, 0, 0, 0, 6.096, 0, 0, 0, 0, 0,
>> 0, 0, 0, 0, 0, 0, 0, 10.668, 7.62, 2.54, 0, 0, 0, 13.462, 8.636, 0, 0,
>> 0, 0, 0, 0, 0, 0, 9.652, 1.778, 2.54, 0, 0, 0, 0, 4.064), D =
>> c(NA_real_, NA_real!
>> > _, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_), !
>> > E = c(0.25, 15.49, 0, 0, 0, 0, 0, 0, 0.25, 0.76, 0.76, 0, 0, 0, 0,
>> > 0, 0, 0, 0, 0, 0, 0, 0, 2.03, 10.41, 32, 2.29, 2.54, 66.29, 10.67,
>> 29.97, 3.81, 23.88, 5.08, 16.76, 12.19, 2.54, 5.33, 0, 0, 0, 0, 0, 0, 0,
>> 0, 0, 7.37, 0, 10.41, 0, 0, 0, 0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.29, 0,
>> 0, 0, 0, 5.08, 0.51, 0, 0, 0, 0, 10.16, 0, 0, 28.7, 0, 0, 0, 0.51,
>> 19.81, 1.02, 0, 0, 0, 0, 0, 0, 0, 2.54, 19.81, 5.59, 12.45, 0.51, 0, 0,
>> 0, 11.18), F = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_,!
>> > NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_ ), G = c(0, 6.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
>> 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.78, 12.95, 25.91, 0, 0.51, 34.04, 3.3,
>> 19.3, 0.76, 13.97, 3.81, 18.29, 9.14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
>> 6.86, 0, 6.86, 0, 0, 0, 1.52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
>> 5.84, 0, 0, 0, 0, 0, 9.65, 0, 0, 37.08, 0, 0, 0, 0, 19.05, 0, 0, 0, 0,
>> 0, 0, 0, 0, 0, 18.29, 12.45, 11.94, 0, 0, 0, 0, 9.4), H = c(NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, !
>> > NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_rea
>> > l_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_), I = c(NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_!
>> > character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character!
>> > _, NA_character_, NA_character_, NA_character_, NA_character_, NA_
>> > character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_), J = c("0.00", "4.32", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "5.33", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "1.78",
>> "0.25", "11.18", "0.00", "0.00", "63.75", "23.11", "11.18", "3.05",
>> "5.59", "0.00", "2.03", "0.25", "4.32", "10.16", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.76", "0.00", "6.10",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00!
>> > ", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "4.83", "19.81",
>> "0.00", "0.00", "0.00", "0.00", "8.89", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "8.38", "4.83", "0.00", "0.76", "0.00",
>> "0.00", "0.00", "0.00", "0.00"), K = c("0.00", "10.67", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "1.27", "0.00", "11.18", "0.00", "0.00", "53.59", "28.70",
>> "19.81", "0.51", "15.49", "1.78", "2.03", "0.25", "1.78", "2.54",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "3.56", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "1.27", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00",!
>> > "0.00", "0.00", "25.40", "0.00", "0.00", "0.00", "0.00", "15.49",
>> > "9.40", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "2.03", "11.94", "2.29", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "9.91"), L = c("0.00", "5.33", "6.60", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "2.79", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "5.08", "0.00", "0.00", "38.86", "24.13", "14.99", "0.00", "13.72",
>> "3.05", "3.05", "0.00", "0.00", "6.35", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "2.29", "0.00", "1.52", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "4.06", "5.08",
>> "0.00", "0.00", "0.00", "8.89", "43.69", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "4.06", "6.60", "4.06", "0.00", "0.00",
>> "0.00", "0.!
>> > 00", "0.00", "6.86"), M = c(NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, !
>> > NA_character_, NA_character_, NA_character_, NA_character_, NA_cha
>> > racter_, NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_), NA. = c(NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_, NA_char!
>> > acter_, NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_ch!
>> > aracter_, NA_character_, NA_character_, NA_character_, NA_characte
>> > r_, NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_), X0 =
>> c(NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, !
>> > NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_), P = c(NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_c!
>> > haracter_, NA_character_, NA_character_, NA_character_, NA_charact
>> > er_, NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_charac!
>> > ter_, NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_), Q = c(NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_rea!
>> > l_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA
>> > _real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_), R = c(NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_r!
>> > eal_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_), S = c("0.00", "4.83", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.51", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "0.00", "0.00", "0.00", "0.00", "14.73", "4.32", "3.56", "57.91",
>> "15.24", "28.45", "10.16", "33.02", "5.08", "9.14", "4.32", "9.65",
>> "8.38", "12.70", "0.00", "0.00", "0.00", "0.00", "9.14", "1.02", "0.00",
>> "0.00", "4.57", "0.00", "7.62", "0.00", "0.00", "0.00", "0.00", "3.05",
>> "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.76",
>> "0.00", "0.0!
>> > 0", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00"
>> > , "0.00", "0.00", "2.54", "7.11", "5.59", "0.00", "0.00", "0.00",
>> "10.16", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
>> "2.29", "10.67", "4.06", "0.00", "0.00", "0.00", "0.00", "9.14",
>> "3.56"), T = c(NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_, NA_ch!
>> > aracter_, NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_,
>> NA_character_, NA_character_, NA_character_, NA_character_), U =
>> c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, !
>> > NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_
>> > real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
>> NA_real_, NA_real_, NA_real_, NA_real_)), .Names = c("Date", "A", "B",
>> "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "NA.", "X0", "P",
>> "Q", "R", "S", "T", "U"), !
>> > row.names = c(NA, 100L), class = "data.frame")
>> > Thankyou,
>> > Eliza
>> > > Date: Mon, 31 Mar 2014 20:04:37 +0100
>> > > From: ruipbarradas at sapo.pt
>> > > To: eliza_botto at hotmail.com; r-help at r-project.org
>> > > Subject: Re: [R] monthly sum
>> > >
>> > > Hello,
>> > >
>> > > Sorry, but I have no idea why the error message, with me it works
>> > > correctly. Are you sure that the four columns A, B, C and D are
>> numeric?
>> > > What does str(dat) say?
>> > >
>> > > Rui Barradas
>> > >
>> > > Em 31-03-2014 19:40, eliza botto escreveu:
>> > > > Dear Rui,
>> > > >
>> > > > Thanks for your reply. But the command seems not to be working.
>> I am
>> > > > getting the following error.
>> > > >
>> > > > Error in FUN(X[[1L]], ...) : invalid 'type' (character) of
>> argument
>> > > >
>> > > > Any idea? :(
>> > > >
>> > > > Thanks,
>> > > >
>> > > > Eliza
>> > > >
>> > > >
>> > > > > Date: Mon, 31 Mar 2014 18:48:08 +0100
>> > > > > From: ruipbarradas at sapo.pt
>> > > > > To: eliza_botto at hotmail.com; r-help at r-project.org
>> > > > > Subject: Re: [R] monthly sum
>> > > > >
>> > > > > Hello,
>> > > > >
>> > > > > Maybe the following will do.
>> > > > >
>> > > > >
>> > > > > library(zoo)
>> > > > > ym <- as.yearmon(dat$Date, "%d-%B-%y")
>> > > > > aggregate(dat[,-1], list(ym), FUN = sum, na.rm = TRUE)
>> > > > >
>> > > > >
>> > > > > Also, please use dput() to post data examples.
>> > > > >
>> > > > > Hope this helps,
>> > > > >
>> > > > > Rui Barradas
>> > > > >
>> > > > > Em 31-03-2014 18:31, eliza botto escreveu:
>> > > > > > Dear useRs,
>> > > > > > I have the data of following format. I have only pasted
>> some part
>> > > > of the data. The data starts from 1961 and ends up in december
>> 1987.
>> > > > > >
>> > > > > > dat <- read.table(text="Date A B C D1-Jan-61 0.00 1.27 8.128
>> > > > 0.252-Jan-61 6.10 9.144 94.742 15.493-Jan-61 0.00 0.508 1.27
>> > > > 0.004-Jan-61 0.00 0 NA 0.005-Jan-61 0.00 0 0 0.006-Jan-61 0.00
>> NA 0
>> > > > 0.007-Jan-61 0.00 0 0 0.008-Jan-61 0.00 NA 0 0.009-Jan-61 0.00
>> NA 0
>> > > > NA10-Jan-61 0.00 4.064 4.826
>> > > > 0.76",sep="",header=TRUE,stringsAsFactors=FALSE)
>> > > > > >
>> > > > > > I need to calculate the sum of each months of A,B,C and D.
>> There
>> > > > are NA's in each column so whenever there is NA it should be
>> ignored.
>> > > > > > In the end we should have a table with 12 values for each
>> year or
>> > > > all the for columns having dimension (12*number of years rows
>> and 4
>> > > > columns).
>> > > > > >
>> > > > > > Thankyou very much in advance
>> > > > > > Eliza
>> > > > > > [[alternative HTML version deleted]]
>> > > > > >
>> > > > > > ______________________________________________
>> > > > > > R-help at r-project.org mailing list
>> > > > > > https://stat.ethz.ch/mailman/listinfo/r-help
>> > > > > > PLEASE do read the posting guide
>> > > > http://www.R-project.org/posting-guide.html
>> > > > > > and provide commented, minimal, self-contained, reproducible
>> code.
>> > > > > >
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list