[R] testing column data against criteria, point by point

Kara Przeczek przeczek at unbc.ca
Thu Mar 5 09:46:17 CET 2009


I am fairly new to R and I would like to do the following, but do not know where to start. Any help or direction would be appreciated.
I have a time series of snow depth measurements. I would like to determine the depth of snowfall for each snowfall event. There is noise in the data so I 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	 FinalTime	
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 column, point by point, to test if (i+1) - i > x. (where I will set x to exlude the noise in the data). As long as i+1 is greater than or equal to i, then the initial depth stays at the first data point and the final value changes to that in i+n. Once the test is false, this indicates the end of the event, the accumulation is calculated, all values are saved as event X and a new event is started.  
I tried using ifelse(), but I do not know how to move through the data and then save the initial and final values and time stamps in another table.
 
Thank you very much for your time.
 
Kara
 
 
 
 




More information about the R-help mailing list