[R] sapply and Date objects

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat May 20 17:45:19 CEST 2006


?sapply  says

        X: list or (atomic) vector to be used.

now dt is neither, and it has been coerced to a list, losing its class.

Reading the help page for the function often resolves such questions.


On Sat, 20 May 2006, Fernando Saldanha wrote:

> This is probably a dumb question, but I cannot figure it out. Why does
> this happen?
>
> dt <- as.Date("1954-02-01")
>> as.character(dt)
> [1] "1954-02-01"
>> sapply(c(dt), as.character)
> [1] "-5813"


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
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



More information about the R-help mailing list