0
votes

I have imported a csv file into r and there is a column which I want to format to date.
The data is as this: "01.01.2018 00:00" in the columns.
I have tried the as.date function but this results in NA's I have tried converting the column to numeric first but then the data is converted to NA's
I have tried a number of ways to get the data formatted but none worked.

I have df$col <- as.POSIXct("21.01.2018 00:00", format = "%d-%m-%y %H:%M")

I keep getting the above error,

character string is not in a standard unambiguous format.

I have read lots on this and I cannot get a resolution so would really appreciate some guidance.

1

1 Answers

0
votes

The format mask you used in as.POSIXct was off. Your day/month/year separator is dot, not dash. Also, use %Y for a 4 digit year, as %y is for a 2 digit year. Use this version:

as.POSIXct("21.01.2018 00:00", format = "%d.%m.%Y %H:%M")

[1] "2018-01-21 CET"