[R] calculation on series with different time-steps

Joris Meys jorismeys at gmail.com
Tue Jul 6 10:54:41 CEST 2010


Look at ?ifelse en ?abs, eg :

data_frame$new_column_in_dataframe <- ifelse(stage$julian_day ==
baro$julian_day & abs(stage$time -
baro$hour) <= 30,
stage$stage.cm - baro$pressure, NA )

Cheers
Joris


On Thu, Jul 1, 2010 at 10:09 PM, Jeana Lee <jeana.lee at colorado.edu> wrote:
> Hello,
>
> I have two series, one with stream stage measurements every 5 minutes, and
> the other with barometric pressure measurements every hour.  I want to
> subtract each barometric pressure measurement from the 12 stage measurements
> closest in time to it (6 stage measurements on either side of the hour).
>
> I want to do something like the following, but I don't know the syntax.
>
> "If the Julian day of the stage measurement is equal to the Julian day of
> the pressure measurement, AND the absolute value of the difference between
> the time of the stage measurement and the hour of the pressure measurement
> is less than or equal to 30 minutes, then subtract the pressure measurement
> from the stage measurement (and put it in a new column in the stage data
> frame)."
>
>                     if ( stage$julian_day = baro$julian_day & |stage$time -
> baro$hour| <= 30 )
>                     then (stage$stage.cm - baro$pressure)
>
> Can you help me?
>
> Thanks,
> JL
>
>        [[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.
>



-- 
Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



More information about the R-help mailing list