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....@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@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.m...@ugent.be ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php ______________________________________________ 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.