I have a csv file which has date in following format.
8/13/2016
8/13/2016
8/13/2016
2016-08-13T08:26:04Z
2016-08-13T14:30:23Z
8/13/2016
8/13/2016
When I import this into R it takes it as a character. I want to convert it into Date format,but when I convert it into date format it takes all NA values
as.Date(df$create_date,format="%m%d%y")
Date field in CSV has different formats in which date is recorded. How can I convert it into date format in R
Best Answer
A base R option (assuming that there are only two formats in the OP's 'create_date' column), will be to create a logical index with
grepl
for those date elements that start with 'year', subset the 'create_date' based on the logical index ('i1'), convert toDate
class separately and assign those separately to aDate
vector of the same length as the number of rows of the dataset to create the fullDate
class.Or as I commented in the OP's post (first)
parse_date_time
fromlubridate
can be useddata