Session Ready
Exercise

Specifying dates

As you saw in the video, R doesn't know something is a date unless you tell it. If you have a character string that represents a date in the ISO 8601 standard you can turn it into a Date using the as.Date() function. Just pass the character string (or a vector of character strings) as the first argument.

In this exercise you'll convert a character string representation of a date to a Date object.

Instructions
100 XP

We've stored the string "2013-04-03" in a variable called x.

  • Use str() to look at the structure of x and confirm it's just a character string.
  • Convert x to a date using as.Date().
  • Use str() to look at the structure of x_date and confirm it's a Date.
  • Now use as.Date() to store the date April 10, 2014.