On Fri, 16 Feb 2007, Marc Schwartz wrote:

On Fri, 2007-02-16 at 15:39 +0000, Sérgio Nunes wrote:
Just for the record, here are my steps for producing a date based histogram.
Data is stored in a file where each line only has a date - 2007/02/16

d<-readLines("filename.dat")
d<-as.Date(d, format="%Y/%m/%d")
pdf(yearly.pdf)
hist(d, "years")
dev.off()

Instead of "years" you can also use "days", "weeks", "months", "secs",
"mins", "hours".

One final question, how could I easily filter my dataset if, for
instance, I only wanted to see results from 2006 ?

Thanks to all who helped,
Sérgio Nunes

The easiest way may be to create your own "Year" extractor function,
since there does not appear to be one by default, unless I missed it
someplace (it is not listed in ?weekdays).

From that help page

Note:

     Other components such as the day of the month or the year are very
     easy to compute: just use 'as.POSIXlt' and extract the relevant
     component.

1900+as.POSIXlt(d2)$year
[1] 2006 2004 2004
...

--
Brian D. Ripley,                  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595
______________________________________________
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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to