Session Ready
Exercise

Date formats (2)

Not only can you convert characters to dates, but you can convert objects that are already dates to differently formatted dates using format():

# The best point move in stock market history. A +936 point change in the Dow!
best_date
[1] "2008-10-13"

format(best_date, format = "%Y/%m/%d")
[1] "2008/10/13"

format(best_date, format = "%B %d, %Y")
[1] "October 10, 2008"

As a reminder, here are the formats:

  • %Y: 4-digit year (1982)
  • %y: 2-digit year (82)
  • %m: 2-digit month (01)
  • %d: 2-digit day of the month (13)
  • %A: weekday (Wednesday)
  • %a: abbreviated weekday (Wed)
  • %B: month (January)
  • %b: abbreviated month (Jan)
Instructions
100 XP
  • The vector char_dates has been created for you
  • Create the vector dates from char_date. Specify the format so R reads them correctly.
  • Modify dates using format() so that each date looks like "Jan 04, 17".
  • Modify dates using format() so that each date looks like "01,04,2017".