On 09/12/12 10:34, CHEN, Cheng wrote:
Hi, guys
I don't understand why I can apply as.Date to a single item in the list:
as.Date(alldays[4])
[1] "29-03-20"
but when I try to lapply as.Date to all the items, i got a sequence of neg
numbers:
sapply(alldays[1:4], FUN=as.Date)
03-04-2012 02-04-2012 30-03-2012 29-03-2012
-718323 -718688 -708492 -708857
does anyone know what's wrong here?
i am very confused!
Thanks a lot for your time in such a freezing weekend!
It's actually a very fine warm sunny weekend here in the
Good Part of the World! :-)
(a) I don't understand the phenomenon you describe either.
(b) However, it seems to me there is no need to us sapply() at
all; just do:
as.Date(alldays)
and you get results as expected. But see below.
(c) You are getting a toadally wrong answer from as.Date(alldays[4]),
if I am reading the output correctly. My understanding is that alldays[4]
is "29-03-2012" and so you *want* to get 2012-03-29 from as.Date
(and *NOT* what you got!).
You need to do as.Date(alldays, format="%d-%m-%Y"). Is it not so?
cheers,
Rolf Turner
______________________________________________
[email protected] 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.