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.

as.POSIXct()

as.POSIXct()

- [Instructor] We've talked about date and time objects in R. So far, we've talked about date, which is a date-only object in R. We've talked about POSIXlt, which is a date and time object in R. We should also talk about POSIXct, which is also a date and time object in R but unlike POSIXlt, POSIXct stores date-time as seconds since January 1st, 1970. Let's take a look. I've typed in a command, as.POSIXct with a string. When I run that command, you'll see that it returns a formatted date-time string. We can confirm that by typing in the same command but let's use the structure command to examine what actually comes out. I'll type an str, parentheses, and you'll see that I have received a POSIXct object. Now, again, POSIXct produces an object that records the date and time in terms of seconds since 1970, January 1st, zero hours, zero minutes, zero seconds. To confirm that, let's place the result of as.POSIXct…

Contents