[R] convert TS dataframe to evenly spaced intervals?

David Winsemius dwinsemius at comcast.net
Tue Jul 26 02:42:55 CEST 2011


On Jul 22, 2011, at 7:01 PM, Derrick Lin wrote:

> Hi R-help,
>
> I have a dataframe consisting of a time-series [t, v]. The  
> timestamps aren't
> at all evenly spaced. The values are continuous. I've been able to  
> graph
> this as a step function (which is what it should be) in ggplot2,  
> using the
> 'step' geom. Now I would like to take the integral of the step  
> function.
>
> For this and other reasons, is there a way to convert this into an  
> evenly
> time-interval-ed array?

If you had provided reproducible code there might have been more  
response. Since you have the data in a dataset it would have been no  
trouble at all to just post dput() applied to the example. Instead,  
here you are 3 days later with no reply.
>
>
> example current dataframe:
>
> t(currently as.POSIXct-ed)             value
> 5/31/11 0:00                                  7.56
> 5/31/11 0:01                                  7.78
> 5/31/11 1:05                                  3.00
> 5/31/11 1:17                                  8.32
>
>
> desired (something like this, anyway):
> t                                                  value
> 5/31/11 0:00                                 7.56
> 5/31/11 0:05                                 7.78
> 5/31/11 0:10                                 7.78
> ...                                                ...
> 5/31/11 1:00                                 7.78
> 5/31/11 1:05                                 3.00
> 5/31/11 1:10                                 3.00
> 5/31/11 1:15                                 3.00
> 5/31/11 1:20                                 8.32

I would have been converting this example to a zoo object and then  
merging with a dataset whose range matched yours but that was on a one  
minute timescale. You could then use the locf interpolation option  
that the zoo functions support and then pickout the 5 minute values  
after the interpolation/

-- 
David.
>
> It could also be factors like: 0:00 - 0:05, 7.56. However I don't  
> think my
> grasp of this is very good. It'd also be great if the solution were  
> general
> purpose so that I can change the parameters as needed (like interval  
> size).
>
> I've been banging my head on #R and begun reading plyr/reshape
> documentation, so I would really appreciate any help!
>
> -Derrick
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list