'Converting string vector to date
I have below vector of string
dates = c('1997 Jan- 6', '1997 Jan-13')
I wish I could have a generic approach so that I can get a date vector from this string.
Is there any straightforward way to do this?
Thanks for your insight
Solution 1:[1]
We can use ymd
library(lubridate)
ymd(dates)
[1] "1997-01-06" "1997-01-13"
Or with base R
as.Date(dates, format = '%Y %b-%d')
[1] "1997-01-06" "1997-01-13"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | akrun |
