[R] strptime Usage

Ko-Kang Kevin Wang kwan022 at stat.auckland.ac.nz
Wed Nov 26 01:23:45 CET 2003


Hi,

I have a column in a dataframe in the form of:
> as.vector(SLDATX[1:20])
 [1] "1/6/1986"  "1/17/1986" "2/2/1986"  "2/4/1986"  "2/4/1986"
 [6] "2/21/1986" "3/6/1986"  "3/25/1986" "4/6/1986"  "4/10/1986"
[11] "4/23/1986" "4/30/1986" "5/8/1986"  "5/29/1986" "6/15/1986"
[16] "6/18/1986" "6/23/1986" "6/29/1986" "7/16/1986" "7/25/1986"

I'd like to convert it into either yyyy-mm or yyyy/mm form, e.g. 1986-06 
or 1986/06, and I've been suggsted to use the strptime() function.  

However when I look at the documentation of it and tried something like:
> strptime(as.vector(SLDATX)[1:20], "%y/%m")
 [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

I got a bunch of NA's.  I also tried:
> strptime(as.vector(SLDATX)[1:20], "%y/%m/%d")
 [1] "2001-06-19" NA           "2002-02-19" "2002-04-19" "2002-04-19"
 [6] NA           "2003-06-19" NA           "2004-06-19" "2004-10-19"
[11] NA           NA           "2005-08-19" NA           NA
[16] NA           NA           NA           NA           NA

It is totally messed up.

I'd really appreciate if anyone can point out where I did wrong *_*!

Many thanks in advance.


-- 
Cheers,

Kevin

---------------------------------------------------------------
"Try not.  Do, do!  Or do not.  There is no try"
   Jedi Master Yoda

----
Ko-Kang Kevin Wang
Master of Science (MSc) Student
SLC Tutor and Lab Demonstrator
Department of Statistics
University of Auckland
New Zealand
Homepage: http://www.stat.auckland.ac.nz/~kwan022
Ph: 373-7599
    x88475 (City)
    x88480 (Tamaki)




More information about the R-help mailing list