[R] Date conversion problem

Newbie19_02 nvanzuydam at gmail.com
Thu Mar 4 17:09:47 CET 2010


Hi All,

I have a character data.frame that contains character columns and date
columns.  I've manage to convert some of my character columns to a date
format using as.Date(x, format="%m/%d/%y").  

An example of one of my dates is 
 PROCHI    DtDeath icdcucd date_admission1 date_admission_2
CAO0004563       <NA>    <NA>      2005-09-01             <NA>
CAO0073505       <NA>    <NA>      1998-03-05             <NA>
CAO0079987       <NA>    <NA>      2002-04-14             <NA>
CAO0182089       <NA>    <NA>      2007-06-10         11/06/07
CAO0194809 17/02/2005     I64      2004-09-04         14/02/05
CAO0204000       <NA>    <NA>      1999-05-31             <NA>
CAO0279999       <NA>    <NA>      1999-07-29             <NA>
CAO0330844 29/11/2001     I64            <NA>             <NA>
CAO0395045       <NA>    <NA>      2007-02-13         14/02/07
CAO0507333       <NA>    <NA>      2005-10-08             <NA>


I have converted date_admission1 from a character to a date.  I used the
same script to convert DtDeath but it returns the dates in this format:

 NA           NA           NA           NA           "0017-02-20"
 [6] NA           NA           "0029-11-20" NA           NA          
[11] NA           NA           "0013-10-20" NA           NA          
[16] NA           "0007-12-20" NA           NA           NA          
[21] NA           NA           NA           NA           NA          
[26] NA           NA           NA           NA           NA          
[31] NA           NA           NA           NA           NA          
[36] NA           NA           NA           NA           NA          
[41] NA           NA           NA           NA           NA          
[46] NA           "0029-01-20" "0018-05-20" NA           NA          
[51] NA           NA           NA           NA           NA          
[56] NA           "0013-07-20" NA           NA           NA          
[61] NA           "0026-07-20" NA           NA           NA          
[66] "0029-04-20" NA           NA           NA           "0012-12-20"
[71] NA           NA           NA           NA           NA          
[76] NA           NA           NA           NA           NA          
[81] NA           NA           "0022-01-20" NA           "0029-05-20"
[86] NA           NA           NA           NA           "0022-02-20"
[91] NA          

I've tried as.Date(as.character(DtDeath, "%d/%m/%y") just in case and have
used different versions of the format (%m/%d/%Y, and the reverse)but still
get the incorrect format.  I'm not sure what the problem is?

Thanks,
natalie
-- 
View this message in context: http://n4.nabble.com/Date-conversion-problem-tp1578296p1578296.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list