Re: [R] while loop syntax help

From: Heikki Kaskelma <>
Date: Mon, 03 Mar 2008 02:31:08 +0200

zack holden:
> I need to sort through a vector (x) and identify the point at which 2 successive values become smaller than the previous value.

x <- c(5,5,7,6,5,4,3)
a=c(diff(x, 1) < 0, FALSE) & c(diff(x, 2) < 0, FALSE, FALSE) a # FALSE FALSE TRUE TRUE TRUE FALSE FALSE which(a) # 3 4 5

Heikki Kaskelma mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 03 Mar 2008 - 12:42:51 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 Please read the posting guide before posting to the list.

list of date sections of archive