My speculation is that Microsoft Excel recognized that as a date and
saved it in the "mm/dd/YYYY" format you saw when reading it into R with
dat=read.csv("myfile.csv").
"str" told you the format. You can convert that from character to
Date using as.Date(dat$mydate, '%m/%d/%Y'), as documented in
help('as.Date').
NOTE: The error message, "character string is not in a standard
unambiguous format" is almost appropriate: In this case, it's clear
that "09/16/2019" refers to month 09, day 16, and year 2019. However,
if it were "09/06/2019", we would not know if it were September 6 or 9
June of 2019. If it were "09/06/08", we would have the added
possibility with the year first, followed by month and day: June 8,
2009. This ambiguity is resolved most forcefully by ISO 8601.
Hope this helps.
Spencer Graves
On 11/4/21 5:30 PM, PIKAL Petr wrote:
Hi
Not sure why the date format was changed but if I am correct R do not read
dates as dates but as character vector. You need to transfer such columns to
dates by asDate. The error is probably from your use two asDate commands.
Cheers
Petr
-----Original Message-----
From: R-help <r-help-boun...@r-project.org> On Behalf Of Val
Sent: Thursday, November 4, 2021 10:43 PM
To: r-help@R-project.org (r-help@r-project.org) <r-help@r-project.org>
Subject: [R] Date
IHi All, l,
I am reading a csv file and one of the columns is named as "mydate"
with this form, 2019-09-16.
I am reading this file as
dat=read.csv("myfile.csv")
the structure of the data looks like as follow
str(dat)
mydate : chr "09/16/2019" "02/21/2021" "02/22/2021" "10/11/2017" ...
Please note the format has changed from YYYY-mm-dd to mm/dd/YYYY
When I tried to change this as a Date using
as.Date(as.Date(mydate, format="%m/%d/%Y" )
I am getting this error message
Error in charToDate(x) :
characte string is not in a standard unambiguous format
My question is,
1. how can I read the file as it is (i.e., without changing the date format) ?
2. why does R change the date format?
Thank you,
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních
partnerů PRECHEZA a.s. jsou zveřejněny na:
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about
processing and protection of business partner’s personal data are available on
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti:
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to
it may be confidential and are subject to the legally binding disclaimer:
https://www.precheza.cz/en/01-disclaimer/
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.