From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

weekdays(), months(), quarters(), Julian()

weekdays(), months(), quarters(), Julian()

From the course: R for Data Science: Lunch Break Lessons

weekdays(), months(), quarters(), Julian()

- [Instructor] R provides some convenient date extraction tools. Let's talk about weekdays, months, quarters, and Julian. For this conversation, I'm going to need a vector. We'll call it mydate, and I'm going to define it in line three. Mydate now equals today's date. In line five, I've used the weekdays command to identify the weekdays in mydate. Well, today is Sunday, and the weekdays function tells me that mydate contains a Sunday. If I add 10 days to mydate, weekdays will tell me that I've just added 10 days to Sunday, which equals Wednesday. Weekdays also handles a vector of multiple dates, and you can see this in line seven. I'm giving weekdays the argument of mydate + 1:5. This provides me with five elements, and I've added one, and then two, and then three, four, five, which gives me Monday, Tuesday, Wednesday, Thursday, Friday. Now there's one more trick to weekdays. I can tell it to use the abbreviation…

Contents