0

My raw data file have the date columns with numbers like "180410". These are read as integers when I import the data into R. Now I tried converting them to dates using as.date but I got only N/A in these columns. Is there a way to covert them to actual dates? Please help

1 Answers1

0

You need to check the format part of as.Date, it needs to match the input (2 digit year, and no spacing). If you have the wrong input you get NA. The following example produces NA because there are no hyphens in your input:

as.Date("180412", "%y-%m-%d")

Use this instead:

as.Date("180412", "%y%m%d")
rg255
  • 4,119
  • 3
  • 22
  • 40