[R] need for help for solving operations in a vector

Makram Belhaj Fraj belhajfraj.makram at gmail.com
Wed Dec 23 08:34:34 CET 2015


 Dear colleagues
i need your generous help to solve the following problem

I have a  soil moisture time series qWC1 (61 values)
> qWC1
 75.33336 75.20617 75.20617 74.95275 74.95275 74.70059 74.70059 74.70059
74.57498 74.44968 74.32469 74.07563  85.57237 90.40123 90.73760 90.73760
90.73760 90.73760 90.90648 91.07582 91.24564 90.90648 86.82135 80.69793
79.30393 78.62058 78.21484 77.81226 77.67876 77.41279 77.28032 76.88495
76.75383 76.75383 76.49260 76.36249  76.23270 76.23270 76.10325 75.97412
75.84532 75.71685  75.71685 75.71685 75.71685 75.46087 75.46087 75.46087
75.33336 75.20617 75.20617 75.20617 75.20617 75.20617 75.20617 75.07930
75.07930 75.07930 74.95275 74.95275  74.95275

I want to measure consecutive increases corresponding to irrigation and
consecutive decreases  corresponding to recharge
I wrote the following code and it does not calculate for each increment in
i?
also note that I choose to not use diff command in time series because I
 want also that "plateaux" corresponding to a minimum of 2 equal
consecutive values are accounted as positive differences=irrigations so
when x[i+1]==x[i] the difference y might be equal to the previous value xi

following the code i wrote

x<-ts(qWC1,start=1, end=61, frequency=1)
x[1]
plot(x, type="h", col = "green")
y<-rep(0,61)
for (i in 1:61) {
if (x[i+1] > x[i]){
    y[i]==x[i+1]-x[i]
} else if (x[i+1]==x[i]){
    y[i]=x[i+2]-x[i]
} else {
    y[i]==x[i+1]-x[i]
}

}
plot(y, type="h", col = "blueviolet")

Many thank
Makram

	[[alternative HTML version deleted]]



More information about the R-help mailing list