[R] monthly sum

William Dunlap wdunlap at tibco.com
Mon Mar 31 21:43:07 CEST 2014


Converting data from a non-R format to R's internal format is a common
place to run into errors.   Use the str() function to examine any data you
read in to make sure R is seeing it the way that you expect.  If that looks ok
try using summary() or plot() for more checks that the data import went
as expected.  Do this before doing any other analysis on the data and you
will avoid a lot of errors later on.

E.g., str(dat) shows that column "A" is character, as are several other columns
that you probably mean to be numeric, which would account for the error
message that you got.

(The output of dput() got mangled a bit in the mail (long lines got broken
in inappropriate places), but I think I got it read in corrrectly.)

> str(dat)
'data.frame':   100 obs. of  22 variables:
 $ Date: chr  "1-Jan-61" "2-Jan-61" "3-Jan-61" "4-Jan-61" ...
 $ A   : chr  "0.00" "6.10" "0.00" "0.00" ...
 $ B   : num  1.27 9.144 0.508 0 0 ...
 $ C   : num  8.13 94.74 1.27 0 0 ...
 $ D   : num  NA NA NA NA NA NA NA NA NA NA ...
 $ E   : num  0.25 15.49 0 0 0 ...
 $ F   : num  NA NA NA NA NA NA NA NA NA NA ...
 $ G   : num  0 6.1 0 0 0 0 0 0 0 0 ...
 $ H   : num  NA NA NA NA NA NA NA NA NA NA ...
 $ I   : chr  NA NA NA NA ...
 $ J   : chr  "0.00" "4.32" "0.00" "0.00" ...
 $ K   : chr  "0.00" "10.67" "0.00" "0.00" ...
 $ L   : chr  "0.00" "5.33" "6.60" "0.00" ...
 $ M   : chr  NA NA NA NA ...
 $ NA. : chr  NA NA NA NA ...
 $ X0  : chr  NA NA NA NA ...
 $ P   : chr  NA NA NA NA ...
 $ Q   : num  NA NA NA NA NA NA NA NA NA NA ...
 $ R   : num  NA NA NA NA NA NA NA NA NA NA ...
 $ S   : chr  "0.00" "4.83" "0.00" "0.00" ...
 $ T   : chr  NA NA NA NA ...
 $ U   : num  NA NA NA NA NA NA NA NA NA NA ...

Bill Dunlap
TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of eliza botto
> Sent: Monday, March 31, 2014 12:12 PM
> To: ruipbarradas at sapo.pt; r-help at r-project.org
> 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.




More information about the R-help mailing list