I have trouble converting double data into a date. I want to convert a date by using as_date. However, when I apply this function, I am getting strange output. I think the problem lays the horizontal line under the numbers (see the image). Does someone know how I can delete this line or escape?
Asked
Active
Viewed 104 times
-1
-
Please dont add links to outside websites and always post your code when seeking helpl. – Cyrus Mohammadian Apr 18 '22 at 19:09
1 Answers
0
One option is to use lubridate
:
library(lubridate)
df$date <- ymd(df$date)
# [1] "1995-10-11" "1995-01-03"
Or use a combination of strptime
and as.Date
:
df$date <- as.Date(strptime(df$date, format = "%Y%m%d"))
Data
df <- structure(list(date = c(19951011, 19950103)), row.names = c(NA,
-2L), class = "data.frame")

AndrewGB
- 16,126
- 5
- 18
- 49