Creating Date objects
The readr
import functions can automatically recognize dates in standard ISO 8601 format (YYYY-MM-DD) and parse columns accordingly. If you want to import a dataset with dates in other formats, you can use parse_date()
.
In this exercise, you'll be working with some weather data. Each date is stored according to American convention: MM/DD/YYYY. In order to specify this format, you'll use %m
for two-digit month, %d
for two-digit day, and %Y
for four-digit year.
This exercise is part of the course
Reading Data into R with readr
Exercise instructions
Parse the date
column of the weather
data frame using parse_date()
. Set the format
argument to "%m/%d/%Y"
and assign the result back to the date
column.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Change type of date column
weather$date <- ___