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
Asked
Active
Viewed 63 times
0
-
`as.Date("180410", "%d%m%y")`, If you have a column use `as.Date(df$column_name, "%d%m%y")`, if the column is an integer, `as.Date(as.character(df$column_name), "%d%m%y")` – Ronak Shah May 23 '18 at 04:59
-
`as.Date(as.character(180410),'%d%m%y')` – ds_user May 23 '18 at 04:59
-
Thank you so much. This worked fine :) – Poorna Sagar May 23 '18 at 07:12
1 Answers
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
-
Thank you. Understood the importance of inputting right format :) – Poorna Sagar May 23 '18 at 07:13