Dear list, I'm trying to write my first looping function in R. After many hours of searching help files and previous posts, I'm at wits end. Please forgive my programming ignorance...any help is greatly appreciated. I need to sort through a vector (x) and identify the point at which 2 successive values become smaller than the previous value. I've written a "while" statement that I think should work. It's should basically say: If value 1 > value 2 and also > value3, then == row(Value 1). Else, go to the next Value. However, output returns "NULL", no matter how I've modified the syntax. Thanks in advance for any help. Zack ############################# x <- c(5,5,7,6,5,4,3) x <- data.frame(x) y <-length(x)-2counter <- 1 output = c() while(counter <= y) { counter1 <- counter+1counter2 <- counter+2 if(x[counter,1] > x[counter1,1]|| x[counter1,1] > x[counter2,1]){output = x[counter, ] } else { counter = counter+1 } counter = y}######################################## [[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.