0

I have a data frame that has columns date and volume.

Trying to sum up the volumes by date i used:

volume_per_month <- aggregate(x ,by = list(x$date), FUN = sum)

I get :

Error in Summary.Date(c(14610, 14610, 14610, 14610, 14610, 14610, 14610, : sum not defined for "Date" objects

Any ideas? I ran this before without problems but used this recently :

lct <- Sys.getlocale("LC_TIME"); 
Sys.setlocale("LC_TIME", "C")

not sure if relate.d

Thanks

Zee Fer
  • 339
  • 4
  • 14
  • Possible duplicate of [R aggregate data.frame with date column](https://stackoverflow.com/questions/24788450/r-aggregate-data-frame-with-date-column) – slamballais Sep 21 '17 at 20:01
  • You are supplying the wrong input: `aggregate(x$volume,by = list(x$date), FUN = sum)`. See the duplicate suggestion. – slamballais Sep 21 '17 at 20:01

1 Answers1

1

Good evening,

It looks like it's trying to sum the date column. I haven't used aggregate in a long time, but this worked for me:

x <- data.frame(date = Sys.Date(), v1 = rnorm(5), v2 = runif(5))
aggregate(x[, setdiff(names(x), "date")] , by = list(x$date), FUN = sum)

Best, Jonny

Jonny Phelps
  • 2,687
  • 1
  • 11
  • 20