Re: [R] Lowest data level since DateX

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat 14 May 2005 - 01:41:48 EST

On 5/13/05, Lapointe, Pierre <Pierre.Lapointe@nbf.ca> wrote:
> Hello,
>
> I'm dealing with financial time series. I'm trying to find out X in this
> sentence:
> The most recent close is the lowest level since X(date).
>
> Here's an example of what I'm looking for:
>
> library(fBasics)
> data(DowJones30)
> tail(DowJones30[,1:5],n=10)
>
> I need to come up with a vector that would look like this
>
> AA AXP T ...
> 2000-12-21 2000-12-20 2000-12-29
>
> i.e. the last date at which the stocks were trading at a lower level than
> the most recent closing.
>
> I know it has to do with min/max, pmin/pmax, cummin/cummax or rev(), but I
> can't figure it out.

The following returns the last index whose value is less than the last entry in vector x (or numeric(0) if none):

> x <- c(1,4,2,6,3)
> tail(which(x < tail(x,1)),1)

[1] 3
> x <- c(1,4,2,6,.5)
> tail(which(x < tail(x,1)),1)

numeric(0)



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat May 14 01:44:24 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:45 EST