0

i got a set of data (1 point each minute) that i want to sum by time but when i apply this code:

library(xts)
a2.xts <- xts(data$data, as.POSIXct(data$time))  
a3.xts <- period.apply(a2.xts, INDEX=endpoints(a2.xts, "mins", k=10), FUN=sum)
head(a3.xts)

i get

2016-11-07 11:35:00   23
2016-11-08 11:45:00   56
2016-11-08 11:55:00   66
2016-11-08 12:05:00   32
2016-11-08 12:15:00   23

but i want it to start from 11:40, 11:50 and so on not 35,45. Thank you

Petr Matousu
  • 3,120
  • 1
  • 20
  • 32
ila tikkral
  • 73
  • 1
  • 1
  • 4
  • Problem is you do not have observations at `11:40`, `11:50`, etc. What you can do is to `merge` with an index that contain those times. Then, the data at those times will be `NA`. Then use `sum` with `na.rm=TRUE`. – aichao Dec 05 '16 at 15:37
  • i have data at 11:40 and every minute. concerning NAs iit was a misktake of my behalf, problem was corrected, thank you – ila tikkral Dec 05 '16 at 16:43
  • [This SO answer](http://stackoverflow.com/a/36827937/496488) might be helpful. – eipi10 Dec 05 '16 at 18:25

0 Answers0