I have a string variable that I want to parse to class Date. In addition to the day, year and month, the format has other characters like separators (,
Date
,
Try this:
as.Date(gsub("[u',()]","",my_data$date), format = '%d %Y %m')
Example with a single string:
d <- "(u'9', u'2005', u'06')" d <- gsub("[u',()]","",d) d.date <- as.Date(d, "%d %Y %m")
Result:
d.date [1] "2005-06-09"