Skip to content
Back to formatted view

Raw Message

Message-ID: <fqfgsf$rbe$1@ger.gmane.org>
Date: 2008-03-03T00:31:08Z
From: Heikki Kaskelma
Subject: while loop syntax help

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