[R] sorting by date
Jeff Jorgensen
jcjorgensen at wisc.edu
Mon Feb 2 23:16:13 CET 2004
Hello,
I have set up a data.frame and one of the columns contains a date of the
form (with slashes as separators):
mm/dd/yyyy
I would like to use formulas on other columns in the data.frame organized
by date, for example:
tapply(var1, sort(date), mean)
However, when I try sort(date) it sorts based on the first two entries in
the date field:
9/1/2001 9/1/2002 9/1/2003 9/2/2001 ...
5.6 7.5 6.4 7.0 ...
Instead of:
9/1/2001 9/2/2001 9/3/2001 9/4/2001 ...
5.6 6.1 7.2 6.8 ...
I would greatly appreciate any help in sorting chronologically. Do I need
to create separate columns for month, day, and year, and then use order()
and then stipulate the hierarchy for which to sort the output? Or, is
there some other more efficient way?
Thanks,
Jeff
More information about the R-help
mailing list