Re: [R] problem converting character to dates

From: Uwe Ligges <ligges_at_statistik.tu-dortmund.de>
Date: Thu, 12 May 2011 19:20:32 +0200

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.



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. Received on Thu 12 May 2011 - 17:28:20 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 13 May 2011 - 15:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive