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]]
Your question seem to me to be not precise enough for us to provide help. Do you need help with the if() syntax? If yes I would advice you to read some introductory R tutorial (like "introduction to R" (pdf, freely avalable on the net)) or some descent textbook. On quick hint for the correct syntax: | denotes OR & denotes AND you need to write == if you want to use the logical "equals" If you do not know how to write the results to some dataframe you should really invest the time to get to know to R by some basic tutorial to understand the basics. By the way, if your timeseries is ordered in the way you describe, a more elegant way would be to create a series consisting of the pressure value belonging to each entry in the stream stage vector (by repeating each single value of pressure 12 times (see ?rep ), and then just substract the two. HTH Jannis Jeana Lee schrieb:> 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. > >
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