On Wed, Jun 16, 2010 at 1:10 PM, skan <juanp...@gmail.com> wrote:
>
> I said taking the first element everyday, but that was just an example, I
> could need one every 2 hours or something more complicated such as one every
> hour if the former one was non null.

Lines <- "1990-01-01 10:00:00 ,  0.900          #  element 1
1990-01-01 10:01:00 ,  0.910          #  element 2
1990-01-01 10:03:00 ,  0.905          #  element 3
1990-01-01 10:04:00 ,  0.905          #  element 4
1990-01-01 10:05:00 ,  0.890          #  element 5
2000-12-30 20:00:00 ,  11.233        # element 3323232"

library(zoo)
z <- read.zoo(textConnection(Lines), sep = ",", tz = "")

# take mean of every 2 hour segment
aggregate(z, as.POSIXct(cut(time(z), "2 hours", include = TRUE)), mean)

For more examples, see:
?aggregate.zoo

______________________________________________
R-help@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.

Reply via email to