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

William Dunlap wdunlap at tibco.com
Wed Dec 23 20:58:25 CET 2015


What answer do you want for the following data?
   x <- c(2,2,3,4,4,4,4,5,5,5,3,1,1,0,0,0,1,1,1)


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Tue, Dec 22, 2015 at 11:34 PM, Makram Belhaj Fraj <
belhajfraj.makram at gmail.com> wrote:

>  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]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list