How to convert data from character to a standard date format in R?

r

#1

I am currently trying to plot a heatmap in R using latitude and longitude given in the data set and time as a third attribute .But in my data , date is in form of character .I want to know how I can convert the date in the form by which R can undertand it.

mvt = read.csv("mvt.csv", stringsAsFactors=FALSE)
 str(mvt)
'data.frame':   191641 obs. of  3 variables:
 $ Date     : chr  "12/31/12 23:15" "12/31/12 22:00" "12/31/12 22:00" "12/31/12 22:00" ...
 $ Latitude : num  41.8 41.9 42 41.8 41.8 ...
 $ Longitude: num  -87.6 -87.7 -87.8 -87.7 -87.6 ...

As we can see that Date attribute is in character form .I want to convert it in the form by which R can understand.


#2

hello @sid100158,

mvt$Date <- as.Date(mvt$Date)

This should do.
Hope this helps!!


#3

train$Date <- as.Date(train$Datetime, “%d-%m-%Y”)

Actually the dates are considered in factor format., this function will convert them into DATE format.