[R] while loop syntax help

Heikki Kaskelma kas.hei at nbl.fi
Mon Mar 3 01:31:08 CET 2008


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



More information about the R-help mailing list