1

Having problems reading a European date format of date.month.year in R using readr, where date and month do not have leading zeros. E.g.

file:

1 date_of_birth
2 1.2.2016 

Tried (among others):

file <- read_csv2("file.csv",col_types = cols(
  date_of_birth=col_date("%d.%m.%Y")
  ))

results in date_of_birth : num 122016

Any help would be appreciated

talat
  • 66,143
  • 20
  • 123
  • 153
kporkka
  • 61
  • 1
  • 4
  • You would probably benefits from defining your own date format before calling read.csv2. See this post: [Specify custom Date format for colClasses argument in read.table/read.csv](http://stackoverflow.com/questions/13022299/specify-custom-date-format-for-colclasses-argument-in-read-table-read-csv). – Joseph Wood Feb 21 '17 at 14:51

1 Answers1

0

Is this what you're after?

> as.Date(gsub("\\.","\\/","1.2.2016"),"%d/%m/%Y")

[1] "2016-02-01"

Carl Boneri
  • 2,509
  • 1
  • 11
  • 15