Skip to content
Prev 140431 / 398506 Next

Range across a List

This statement:

temp<-lapply(split(DF1,DF1$Trade.Date), function(.df) {
+
data.frame(DATE=.df$Trade.Date,RANGE=max(.df$New.Price)-min(.df$New.Pric
e))
+ })

has many results for DATE and one for RANGE; that is the reason you
are getting multiple copies.  Instead you need to write:

temp<-lapply(split(DF1,DF1$Trade.Date), function(.df) {
+
data.frame(DATE=.df$Trade.Date[1],RANGE=max(.df$New.Price)-min(.df$New.Pric
e))
+ })

where you only that the first ([1]) instance of Trade.Date

For the tapply, you can write:

nn=tapply(DF1$New.Price, DF1$Trade.Date, function(.x) max(.x) - min(.x))
On Wed, Mar 26, 2008 at 5:22 PM, Ravi S. Shankar <ravis at ambaresearch.com> wrote: