Storing, creating, displaying, and converting time.
What are the results of the following operations?
01:00
A method to measure time as the number of seconds1 that have elapsed since midnight UTC on 1 January 1970, the Unix epoch.
Examples:
| Date Time (UTC) | Unix Time |
|---|---|
| 12:01 am Jan 1, 1970 | 60 |
A method to measure time as the number of seconds1 that have elapsed since midnight UTC on 1 January 1970, the Unix epoch.
Examples:
| Date Time (UTC) | Unix Time |
|---|---|
| 12:01 am Jan 1, 1970 | 60 |
| 12:01 am Jan 2, 1970 | 86460 |
A method to measure time as the number of seconds1 that have elapsed since midnight UTC on 1 January 1970, the Unix epoch.
Examples:
| Date Time (UTC) | Unix Time |
|---|---|
| 12:01 am Jan 1, 1970 | 60 |
| 12:01 am Jan 2, 1970 | 86460 |
| 7 pm Oct 22, 2025 (today at noon) | 1761159600 |
A method to measure time as the number of seconds1 that have elapsed since midnight UTC on 1 January 1970, the Unix epoch.
Examples:
| Date Time (UTC) | Unix Time |
|---|---|
| 12:01 am Jan 1, 1970 | 60 |
| 12:01 am Jan 2, 1970 | 86460 |
| 7 pm Oct 22, 2025 (today at noon) | 1761159600 |
| 5:55 pm Dec 7, 1941 | −8993325700 |
POSIXct (Portable Operating System Interface Calendar Time) is an atomic vector to store date-times that is built on top of a double vector.
Use as.POSIXct() to create a date-time vector from a numeric (in Unix Time) or a string in a particular format.


Use as.POSIXct() to create a date-time vector from a numeric (in Unix Time) or a string in a particular format.
[1] "1970-01-01 00:01:00 UTC"
[1] "1970-01-01 00:01:00 UTC"
lubridate[1] "1970-01-01 00:01:00 UTC"
lubridate() has many functions that can parse the year (y), month (m), day (d), hour (h), minute (m), and second (s) components of a date-time string.
You can extract components of the date-time object using year(), month(), week(), day(), wday(), hour(), etc.
You can extract components of the date-time object using year(), month(), week(), day(), wday(), hour(), etc.
[1] Thu
Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
You can extract components of the date-time object using year(), month(), week(), day(), wday(), hour(), etc.
[1] Thursday
7 Levels: Sunday < Monday < Tuesday < Wednesday < Thursday < ... < Saturday
You can set those same components in an existing date-time object using change-in-place notation.
Question: Write the (lines) of code necessary to determine:
02:00
What is the average month of these observations?
# A tibble: 6 × 2
month year
<dbl> <dbl>
1 2 2025
2 1 2025
3 2 2025
4 11 2024
5 12 2024
6 12 2024
What is the month of the average of these dates?
# A tibble: 6 × 3
month year datetime
<dbl> <dbl> <dttm>
1 2 2025 2025-02-15 00:00:00
2 1 2025 2025-01-15 00:00:00
3 2 2025 2025-02-15 00:00:00
4 11 2024 2024-11-15 00:00:00
5 12 2024 2024-12-15 00:00:00
6 12 2024 2024-12-15 00:00:00
What is the month of the average of these dates?
# A tibble: 1 × 1
avg_datetime
<dttm>
1 2025-01-04 20:00:00
What is the month of the average of these dates?
# A tibble: 1 × 2
avg_datetime mon_of_avg
<dttm> <dbl>
1 2025-01-04 20:00:00 1
