[R] while loop syntax help

From: zack holden <zack_holden_at_hotmail.com>
Date: Fri, 29 Feb 2008 20:53:28 +0000

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_at_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. Received on Fri 29 Feb 2008 - 20:55:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 03 Mar 2008 - 13:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive