0

I have an Integer overflow error with the rollmean function. It's working well when I am doing it on 5 numbers section but not working on a 20 (and 260) number sections.

Numbers are trading volumes (7 digits).

Do you have any clue to solve this problem?

thanks

SP_stock$mean_vol_20<-ave(SP_stock$vol, SP_stock$ticker, FUN=function(x) rollmean(x,k=20, na.pad=T, align="right"))

Error: In sum(xu[1:k]) : dépassement d'entier - utiliser sum(as.numeric(.))
Error: In sum(xu[1:k]) : Integer overflow - use sum(as.numeric(.))
Jaap
  • 81,064
  • 34
  • 182
  • 193
  • 1
    Welcome to StackOverflow! Please read the info about [how to ask a question](http://stackoverflow.com/help/how-to-ask) and how to produce a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). This will make it much easier for others to help you. – Jaap Jun 04 '14 at 20:18

1 Answers1

1

The clue to your problem is already in the error message. You've to provide numeric input to rollmean instead of integer input here, as the intermediate calculation (sum) overflows when x is integer.

In your case, doing:

ave(as.numeric(SP_stock$vol), SP_stock$ticker, FUN = ...)

should work.

Arun
  • 116,683
  • 26
  • 284
  • 387