[S] Summary of My Avoiding a Loop Question

Humbolt, Allen (HumboltA@kochind.com)
Fri, 19 Jun 1998 13:43:44 -0500


Thanks to Dan Elliott, Brian Ripley, David Lansky, Jean Adams, Andrey
Feuerverger, Gardar Johannesson, Bill Dunlap, and Peter Malewski for their
responses to my question. Several had the same idea of applying cummin to
the reversed Day series. The most compact representations came from Brian
Ripley and Peter Malewski, so I'll present their versions below where the
name of my data frame is called mydat.

Brian Ripley
> unlist(lapply(split(mydat$Price, mydat$Month), function(x)
rev(cummin(rev(x)))))

Peter Malewski
> rev(unlist(rev((tapply(rev(mydat$Price), rev(mydat$Month), FUN=function(x)
cummin(x))))))

Thanks for all of the help.

Allen Humbolt
Quantitative Analyst
Koch Industries, Inc.
HumboltA@kochind.com

ORIGINAL QUESTION BELOW
In the example below I would like to calculate for each Day within each
Month the minimum Price that occurred on or after that Day within that
Month. A loopless solution, anyone?

| DESIRED RESULT
Month Day Price | MinPrice
|
1 25 45 | 45
1 26 50 | 48
1 29 48 | 48
1 30 49 | 49

2 29 50 | 50
2 30 52 | 51
2 31 51 | 51

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news