Skip to content
Prev 347828 / 398500 Next

Still trying to avoid loops

A potential problem with
   ave(dat_2$D, dat_2$S, FUN=order)
is that it will silently give the wrong answer
or give an error if dat_2$D is not numeric.

E.g., if D is a Date vector we get
  > dat_3 <- dat_2[,1:2]
  > dat_3$D <- as.Date(paste0("2015-02-", dat_2$D))
  > with(dat_3, ave(D, S, FUN=order))
  Error in as.Date.numeric(value) : 'origin' must be supplied

Another problem is that it may take a lot more time than
is required if you have a lot of small groups in your data.

Both of those are avoided if you sort the entire dataset first
and 'unsort' the results when putting them into dataset.




Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Wed, Feb 4, 2015 at 12:53 PM, David L Carlson <dcarlson at tamu.edu> wrote: