There are probably many mistakes with this code. I am used to coding in C with a debugger, so I am very new to coding in R without one and different syntax. My code in the upper left panel of R Studio isz<-c(3,1,4,5,2,1,0,3,5,8)zlength(z)y<-c(0,0,0,0,0,0,0,0,0,0)ylength(y)zdiff = diff(z)zdiffn<-length(zdiff)nx<-zdifff<-function(x) { for (k in 1:n){ for (i in 1:n-k){ if (all(x[i] * x[i-1] > 0) && ((x[i+k+1] * x[i+k]) < 0) y[k]<-y[k]+1 } } return(y)}f(x)__________I get back > z [1] 3 1 4 5 2 1 0 3 5 8> length(z)[1] 10> y<-c(0,0,0,0,0,0,0,0,0,0)> y [1] 0 0 0 0 0 0 0 0 0 0> length(y)[1] 10> zdiff = diff(z)> zdiff[1] -2 3 1 -3 -1 -1 3 2 3> n<-length(zdiff)> n[1] 9> x<-zdiff> > f<-function(x) + {+ for (k in 1:n){+ for (i in 1:n-k){+ if (all(x[i] * x[i-1] > 0) && ((x[i+k+1] * x[i+k]) < 0)+ y[k]<-y[k]+1 Error: unexpected symbol in:" if (all(x[i] * x[i-1] > 0) && ((x[i+k+1] * x[i+k]) < 0) y"> }Error: unexpected '}' in " }"> > }Error: unexpected '}' in " }"> return(y)Error: no function to return from, jumping to top level> }Error: unexpected '}' in "}"> f(x)Error in if (all(x[i] * x[i - 1] > 0) && ((x[i + k + 1] * x[i + k]) < : missing value where TRUE/FALSE needed_________Perhaps there is someway to use NULL or NA?
-- View this message in context: http://r.789695.n4.nabble.com/Newbie-code-to-count-runs-of-up-or-down-moves-tp4662423.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list 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.