[R] problem converting character to dates
Uwe Ligges
ligges at statistik.tu-dortmund.de
Thu May 12 19:20:32 CEST 2011
On 12.05.2011 17:40, Assu wrote:
> Hi all,
>
> I've searched this problem and still I can't understand my results, so here
> goes:
>
> I have some time series I've imported from excel with the dates in text
> format from excel. Data was imported with RODBC, sqlQuery() function.
>
> I have these dates:
>> adates
> [1] "01/2008" "02/2008" "03/2008" "04/2008" "05/2008" "06/2008" "07/2008"
> [8] "08/2008" "09/2008" "10/2008" "11/2008" "12/2008" "13/2008" "14/2008"
> I want the format week/year, so I do:
>> as.Date(adates,format=c("%W/%y"))
> and get
> [1] "2020-05-12" "2020-05-12" "2020-05-12" "2020-05-12" "2020-05-12"
> [6] "2020-05-12" "2020-05-12" "2020-05-12" "2020-05-12" "2020-05-12"
> everything is equal to this: 2020-this month-today
>
> if I use strptime(dates, "%W/%y")
1. you need an upper case Y
2. you need a weekday (otherwise the result is not well defined and you
get "today" as the default)
hence
strptime(paste("0", adates, sep="/"), "%w/%W/%Y")
should work.
Uwe Ligges
> it's the same.
>
> Can you explain why this happens and how to solve it?
> Thanks in advance
> Assu
>
> --
> View this message in context: http://r.789695.n4.nabble.com/problem-converting-character-to-dates-tp3517918p3517918.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.
More information about the R-help
mailing list