课程: R for Data Science: Lunch Break Lessons

免费学习该课程!

今天就开通帐号,24,100 门业界名师课程任您挑!

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

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…

内容