I have several .csv files 1 for each year from 2001 to 2018 each with a date column. They all are in m/d/y format in excel. When I read the files into R with
read.csv(x, stringsAsFactors = FALSE)
each file is correctly converted to y-m-d format for the date column except for the year 2018, which keeps it in the same m/d/y format.
This is an issue when I try to bring the dates into Lubridate because the m/d/y format is not compatible.
I am unsure why only the year 2018 is having this problem.
I have tried copying and pasting the dates into the numerical excel format and importing them into R with read.csv. I have copy and pasted in text format. I have also opened up a new excel and csv file and copied the data into those files. I also manually typed 2018 dates and imported into R with read.csv.
It is possible to fix this by:
y <- read.csv(g, stringsAsFactors = FALSE) %>%
as.tibble()
y$date <- gsub("/", "-", y$date)
y$date <- parse_date_time(y$date, orders = c('mdy', 'ymd'))
y$date <- as_date(y$date)
But I find this disconcerting and would like to know why excel does this for 2018 only and if others are have encountered this.
This is an example of what my 2001.csv file looks like after
y <- read.csv(x, stringsAsFactors = FALSE) %>%
as.tibble()
y
# # A tibble: 24 x 4
# date species Site_Code number
# <chr> <chr> <int> <int>
# 1 2001-08-11 WN 23 0
# 2 2001-10-12 WN 23 0
# 3 2001-01-11 EEE 27 0
And this is what the 2018.csv file looks like after being read in with the same code as above:
# A tibble: 84 x 4
date species Site_Code number
<chr> <chr> <int> <int>
1 4/16/2018 EEE 23 0
2 4/30/2018 EEE 23 1
3 5/7/2018 EEE 23 0
No error messages are generated