[R] Help with loop

Hefri helenefrigstad at hotmail.com
Wed Nov 21 17:39:05 CET 2012


Hi,

I have used R for some time, but managed to avoid writing  loops. But this
time I am afraid there is no way around it. 

I have a dataframe with time and salinity (see below). I would like to
extract the time intervals where salinity changes by less than 0.05. So
using the values below this would mean that a subset was made from
2003-07-19 to 2003-07-24, where the change in salinity exceeded 0.05, and
then stating again from 2003-07-24. In other words, I want to make subset of
the time intervals where the one variable stays stabile within a certain set
range. 

> head (D, 10)
       Salt       time
1  35.65114 2003-07-19
2  35.64226 2003-07-20
3  35.62411 2003-07-21
4  35.62473 2003-07-22
5  35.65893 2003-07-23
6  35.70140 2003-07-24
7  35.62157 2003-07-25
8  35.64122 2003-07-26
9  35.63515 2003-07-27
10 35.63798 2003-07-28

Is this possible? Can some please help with how I need to write the loop to
achieve this?

Many thanks, Helen




--
View this message in context: http://r.789695.n4.nabble.com/Help-with-loop-tp4650313.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list