[R] sapply and Date objects

Gabor Grothendieck ggrothendieck at gmail.com
Sat May 20 17:15:18 CEST 2006


>From ?sapply we see that sapply requires a list or
atomic vector.   If its not a list then looking at the first
few two lines of sapply we see it tries to convert
the first arg to a list using as.list.  Note that using
your dt:

> as.list(dt)
[[1]]
[1] -5813

so try this instead:

sapply(list(dt), as.character)



On 5/20/06, Fernando Saldanha <fsaldan1 at gmail.com> 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"
>
> Thanks.
>
> FS
>
> ______________________________________________
> R-help at 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
>



More information about the R-help mailing list