[R] as.Date with characters error
Liz Hare
doggene at earthlink.net
Tue Jul 30 18:24:46 CEST 2013
Oh! Thank you so much! Sorry to have bothered everyone with this!
Liz
On 7/30/2013 12:16 PM, arun wrote:
> Hi,
> Did you checked after removing "e" from "formate"?
>
> ortho$test.dat <- as.Date(ortho$xray.date, formate="%d-%b-%y")
>
> A.K.
>
>
> ----- Original Message -----
> From: Liz Hare <doggene at earthlink.net>
> To: r-help at r-project.org
> Cc:
> Sent: Tuesday, July 30, 2013 12:00 PM
> Subject: [R] as.Date with characters error
>
> Hello,
>
> I'm trying to convert dates in the format dd-mmm-yy using as.Date.
> I have two columns like this, and it works on one but not on the other.
>
>> options(stringsAsFactors=FALSE)
>> ortho <- read.csv("test1.csv", header=TRUE, nrows=10)
>> ortho
> DogID BirthDate xray.date
> 1 11877 23-Aug-87 15-Feb-88
> 2 11877 23-Aug-87 15-Feb-88
> 3 3599 21-Feb-87 21-Feb-88
> 4 3599 21-Feb-87 21-Feb-88
> 5 3599 21-Feb-87 21-Feb-88
> 6 3599 21-Feb-87 21-Feb-88
> 7 3599 21-Feb-87 21-Feb-88
> 8 9563 29-Jun-87 29-Jun-88
> 9 9563 29-Jun-87 29-Jun-88
> 10 9563 29-Jun-87 29-Jun-88
>> ortho$bdat <- as.Date(ortho$BirthDate, format="%d-%b-%y")
>> ortho$bdat
> [1] "1987-08-23" "1987-08-23" "1987-02-21" "1987-02-21" "1987-02-21"
> [6] "1987-02-21" "1987-02-21" "1987-06-29" "1987-06-29" "1987-06-29"
>> ortho$test.dat <- as.Date(ortho$xray.date, formate="%d-%b-%y")
> Error in charToDate(x) :
> character string is not in a standard unambiguous format
>> sessionInfo()
> R version 3.0.1 (2013-05-16)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>>
>
> Does anyone have a guess about what's going on? I've googled for this
> error but haven't found any where the problem is with this type of
> conversion.
>
> Thanks,
> Liz
>
More information about the R-help
mailing list