[R] Odp: testing column data against criteria, point by point
petr.pikal at precheza.cz
Thu Mar 5 13:57:00 CET 2009
r-help-bounces at r-project.org napsal dne 05.03.2009 09:46:17:
> I am fairly new to R and I would like to do the following, but do not
> where to start. Any help or direction would be appreciated.
> I have a time series of snow depth measurements. I would like to
> depth of snowfall for each snowfall event. There is noise in the data so
> only want to add data values if the subsequent depth is greater than the
> previous by a certain margin. I am only interested in calculating snow
> accumulation events.
> Example data:
> Time depth
> 1 84.3
> 2 84.5
> 3 86
> 4 86.1
> 5 85.8
> 6 86.7
> 7 87.9
> 8 89.1
> 9 90
> 10 89
> 11 88
> 12 88
> 13 89.1
> 14 90
> 15 91.2
> 16 89.9
> ... ...
> I would like to create a second data frame from the data that looks
something like this:
> Event InitialDepth FinalDepth Accumulation InitialTime
> 1 84.3 90 5.7 1 9
> 2 88 91.2 3.2 11 15
> I would like to write a program that progresses through the depth
> point by point, to test if (i+1) - i > x. (where I will set x to exlude
> noise in the data). As long as i+1 is greater than or equal to i, then
> initial depth stays at the first data point and the final value changes
> that in i+n. Once the test is false, this indicates the end of the
> accumulation is calculated, all values are saved as event X and a new
> I tried using ifelse(), but I do not know how to move through the data
> then save the initial and final values and time stamps in another table.
It is probably possible but I would use rle and cumsum
# which of the data are increasing
# what is first depth of increasing interval
# what is last depth of increasing interval
# what is accumulation
 1.8 4.2 3.2 -3.8
the similar applies to evaluation which are first and last times of events
and/or its duration.
> Thank you very much for your time.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help