课程: R for Data Science: Lunch Break Lessons

免费学习该课程!

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

format()

format()

- [Narrator] We've talked about as.Date and as.POSIXlt and as.POSIXct and ISOdate. And these are all tools for converting date strings, or in the case of ISOdate, numeric representations of dates, into date objects. What if you wanted to take a date object and format it for output? Well, for that we use format and strftime, and let's take a look at those two. The first thing I've done here is I've created a vector called "myDatetime" and into it I've placed Sys.time. Let's take a look at myDatetime. No surprise, it contains a standard date-time string. But let's say all we're interested in is the year and the date. I can output that with format(myDate), and I'll give it a format string, just like I used when I was interpreting this for input. So I'll put in "% year" and let's put in an ellipsis and then "%d," and that gives me the year and the date, the 15th of the month. By the way, the default format…

内容