1

I am currently trying to convert a list of written dates to objects of type "Date". My dates are in the following format: 1 January 1800. The function i tried to write to convert this to a date object is as.Date("1 January 1800", "%d %B %Y"). Now here comes the weird thing. For the monhts April, September, November and December this code works. For all other months however it doesn't. I am very confused as to why this is happening and would like to get your insights on this problem.

Code with results for all months:

> as.Date("1 January 1872", "%d %B %Y")
[1] NA
> as.Date("1 February 1872", "%d %B %Y")
[1] NA
> as.Date("1 March 1872", "%d %B %Y")
[1] NA
> as.Date("1 April 1872", "%d %B %Y")
[1] "1872-04-01"
> as.Date("1 May 1872", "%d %B %Y")
[1] NA
> as.Date("1 June 1872", "%d %B %Y")
[1] NA
> as.Date("1 July 1872", "%d %B %Y")
[1] NA
> as.Date("1 August 1872", "%d %B %Y")
[1] NA
> as.Date("1 September 1872", "%d %B %Y")
[1] "1872-09-01"
> as.Date("1 October 1872", "%d %B %Y")
[1] NA
> as.Date("1 November 1872", "%d %B %Y")
[1] "1872-11-01"
> as.Date("1 December 1872", "%d %B %Y")
[1] "1872-12-01"
Micha
  • 31
  • 6
  • 4
    It is working fine for me. It could be an issue on your locale – akrun Mar 28 '19 at 12:34
  • 1
    you probably have the wrong locale. It always uses the current locale // EDIT: With `readr` `library(readr); parse_date("1 January 1872",format="%d %B %Y",locale=locale(date_names="en"))` – Julian_Hn Mar 28 '19 at 12:35
  • 1
    You guys are indeed right! My locale was set to dutch time which meant that only april, september, november were being correctly parsed since they are written the same way in dutch. Thank you for the quick answers! – Micha Mar 28 '19 at 13:02

0 Answers0