Dean Dean - 1 year ago 85
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).

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

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 Source


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download