Dean Dean - 1 month ago 5
R Question

When reading CSV in R, how do you keep the time and date format the same?

My CSV looks as follows like this

But when I read it in R, it changes the format for Date and Time(most important issue).
This

Here is my simple code that I used to read the csv

library(readr)
dat1<- read_csv("2010.csv")


How can I make it so that the format for date and time doesn't change and looks like the first picture?

Answer

Try:

dat1 <- read.table("2010.csv", sep = ",", header = T)

If this answer goes wrong, then:

First check exactly what's in your .csv by opening it with text or some code editors instead of Excel or something like that. The problem I think maybe is that some APP like MS Excel, it will do some auto format converting in preview mode, so what you saw may be not what's really in your file.

For example: 2015-1-1 in .csv when open with Excel, it becomes 2015/1/1

Comments