Use %Y (upper case) for 4 digit years

On Wed, Jan 6, 2010 at 10:25 AM, Larry White <ljw1...@gmail.com> wrote:

> Hi, I'm reading data from a text file and transforming it in R and my date
> column seems to be getting corrupted. Can someone point out what's wrong?
> This code worked fine until I added a new date in 2010.
>
> thank you.
>
>
> To load the data I run:
> work_table = read.table(datafilename,header=TRUE)                  #read
> the
> data file
> attach(work_table)                                                 #attach
> the file for ease of use
> names(work_table) =
> c(     "cur_date", "week", "time_pct", "compl", "work_delta",
> "mean_delta", "balance", "total", "total_delta",
> "work", "index", "mean_pd_per_day")
>
> If I list the date element cur_date, I get:
> > work_table$cur_date
>  [1] 8/17/2009  8/30/2009  9/6/2009   9/13/2009  9/20/2009  9/27/2009
>  [7] 10/4/2009  10/13/2009 10/20/2009 10/27/2009 11/3/2009  11/10/2009
> [13] 11/17/2009 11/24/2009 12/2/2009  12/9/2009  12/16/2009 12/23/2009
> [19] 12/30/2009 1/6/2010
>
> This is correct.
>
>
> The line that produces the bad output is:
> dt <-strptime(as.character(work_table$cur_date), "%m/%d/%y")
>
> when I list dt I get:
> >dt
>  [1] "2020-08-17" "2020-08-30" "2020-09-06" "2020-09-13" "2020-09-20"
>  [6] "2020-09-27" "2020-10-04" "2020-10-13" "2020-10-20" "2020-10-27"
> [11] "2020-11-03" "2020-11-10" "2020-11-17" "2020-11-24" "2020-12-02"
> [16] "2020-12-09" "2020-12-16" "2020-12-23" "2020-12-30" "2020-01-06"
>
> The inside function as.character seems to provide correct output
> >
> > as.character(work_table$cur_date)
>  [1] "8/17/2009"  "8/30/2009"  "9/6/2009"   "9/13/2009"  "9/20/2009"
>  [6] "9/27/2009"  "10/4/2009"  "10/13/2009" "10/20/2009" "10/27/2009"
> [11] "11/3/2009"  "11/10/2009" "11/17/2009" "11/24/2009" "12/2/2009"
> [16] "12/9/2009"  "12/16/2009" "12/23/2009" "12/30/2009" "1/6/2010"
>
> which makes me think I'm doing something wrong in my strptime() call.
> as.character(bug_table$rep_date)
>
> Thanks very much for your help
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to