0
$\begingroup$

How do you read a date in R that is given in the following way:

01.01.2019 00:00

While reading it with read.csv("my_file.csv", sep = ";", dec = ",") I am getting the date column as a "factor" class. I am tring to figure how to read this data time data as a date. Any thoughts?

Thank you!

$\endgroup$
1
$\begingroup$

You can use this method (assuming that 'time' is the column you want, and the date format is Date.Month.Year Hour:Minute):

d <- read.csv("my_file.csv", sep = ";", dec = ",")
strptime(as.character(d$time), format="%d.%m.%Y %H:%M")
$\endgroup$
1
$\begingroup$

You can use the library readr, part of the tidyverse.

my_data<- read_delim("my_file.csv", delim = ";", escape_double = FALSE, col_types = cols(date = col_datetime(format = "%d.%m.%Y %H:%M")), 
    locale = locale(decimal_mark = ","), 
    trim_ws = TRUE)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.