Aggregate in R using date as key

Asked

Viewed 152 times

0

Good afternoon,

I’m using the code:

soma<-aggregate(as.numeric(coop[c(10,18,26,34,42,50,58,66)]), by=list(coop$data), FUN=sum, na.rm=TRUE)

to aggregate the data based on the date key, which is in date format. I tried to change this variable to numeric or string, but returns the same error:

Error in aggregate(as.numeric(coop[c(10, 18, 26, 34, 42, 50, 58, 66)]),:
(list) object cannot be coerced to type 'double'

What should I be doing? I have done several other races and I had not come across this error. There are values in NA at the base, but I do not believe that this is the problem.

  • Try to make your code playable!

  • coopdoes not seem to me to be a vector, but rather a data.frame. Therefore, it seems to me that you need to select which column you are aggregating. The way you’re doing: coop[c(...)] you are selecting several lines of a data.frame (which is equal to a list) and cannot be converted to a numeric value.

  • The problem is when converting Coop[c(...)] into numeric.

  • yes, because this cannot be converted to numeric: it is a data.frame. which gives class(coop[c(...)])

  • You’re right. Silly me. I took and turned everything into numerical: data[,10:67]<-sapply(data[,10:67], as.)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.