To convert to date, as long as you successfully imported the data already into a data frame such as dusted
or geov
, and have time2
holding dates as strings resembling 10-27-06
, try:
geov$time2 = as.Date(geov$time2, "%m-%d-%y")
- equal sign
=
used just to save on typing. It is equivalent to <-
, so you can still use <-
if you prefer
- this stores the converted dates right back into
geov$time2
, overwriting it, instead of creating a new variable geov$newdate
as you did in your original question. This is because a new variable is not required for conversion. But if for some reason you really need a new variable, feel free to use geov$newdate
- similarly, you also didn't need to copy
dusted
to a new geov
data frame just to convert. It does save time for testing purposes though, just in case the conversion doesn't work you can restart from copying dusted
to geov
instead of having to re-import data from a file into dusted
Additional resources
help(strptime)
for looking up date code references such as %y
. On Linux, man date
can reveal the date codes