Skip to content
Back to formatted view

Raw Message

Message-ID: <814a72360bbc4c5ab55c53da7588e0ec@SRVEXCHCM1302.precheza.cz>
Date: 2021-11-04T22:30:39Z
From: PIKAL Petr
Subject: Date
In-Reply-To: <CAJOiR6YHWa0biFAgR-e+RkbNUyKuMr+7u1Z4A-KObS+iVwRW_w@mail.gmail.com>

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-bounces at r-project.org> On Behalf Of Val
Sent: Thursday, November 4, 2021 10:43 PM
To: r-help at R-project.org (r-help at r-project.org) <r-help at 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 at 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/