as.Date function error

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

as.Date function error

Wonjae Lee
Hi,

I have some problems with as.Date function.
After I applied as.Date for my data, "2010" changed to "2020" as below
Where am I wrong?

Thanks

Wonjae

> x=c("11/16/2010","11/17/2010","11/18/2010","11/19/2010")
> x=as.Date(x,"%m/%d/%y")
> x
[1] "2020-11-16" "2020-11-17" "2020-11-18" "2020-11-19"

my R veision is 2.12.2.
Reply | Threaded
Open this post in threaded view
|

Re: as.Date function error

djmuseR
as.Date(x,"%m/%d/%Y")
[1] "2010-11-16" "2010-11-17" "2010-11-18" "2010-11-19"

Notice the Y (four digit date).

Dennis

On Sun, Apr 17, 2011 at 6:34 AM, Wonjae Lee <[hidden email]> wrote:

> Hi,
>
> I have some problems with as.Date function.
> After I applied as.Date for my data, "2010" changed to "2020" as below
> Where am I wrong?
>
> Thanks
>
> Wonjae
>
>> x=c("11/16/2010","11/17/2010","11/18/2010","11/19/2010")
>> x=as.Date(x,"%m/%d/%y")
>> x
> [1] "2020-11-16" "2020-11-17" "2020-11-18" "2020-11-19"
>
> my R veision is 2.12.2.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/as-Date-function-error-tp3455466p3455466.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: as.Date function error

Achim Zeileis-4
In reply to this post by Wonjae Lee
On Sun, 17 Apr 2011, Wonjae Lee wrote:

> Hi,
>
> I have some problems with as.Date function.
> After I applied as.Date for my data, "2010" changed to "2020" as below
> Where am I wrong?

You used %y (two-digit year, here: "20" and then expanded to "2020")
instead of %Y (four-digit year, here "2010").

Using as.Date(x,"%m/%d/%Y") yields the desired result.
Z



> Thanks
>
> Wonjae
>
>> x=c("11/16/2010","11/17/2010","11/18/2010","11/19/2010")
>> x=as.Date(x,"%m/%d/%y")
>> x
> [1] "2020-11-16" "2020-11-17" "2020-11-18" "2020-11-19"
>
> my R veision is 2.12.2.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/as-Date-function-error-tp3455466p3455466.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.