1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate R for Finance

Exercise

months() and weekdays() and quarters(), oh my!

As a final lesson on dates, there are a few functions that are useful for extracting date components. One of those is months().

my_date <- as.Date("2017-01-02")

months(my_date)
[1] "January"

Two other useful functions are weekdays() to extract the day of the week that your date falls on, and quarters() to determine which quarter of the year (Q1-Q4) that your date falls in.

Instructions

100 XP
  • A vector of dates has been created for you.
  • Extract the months() from these dates.
  • Extract the quarters() from these dates.
  • Another vector, dates2 has also been created for you.
  • Use weekdays() to determine what day of the week the dates fell on, and assign them to the names of dates2 using names().
  • Print dates2.