Hi, I have these columns that in my excel are hours and minutes (for example, '3:00:00') but R imported them incorrectly as dates (following the example above, '1899-12-31 03:00:00:00').
C7.1 | C7.2 | C7.3 |
---|---|---|
3:00:00 | 2:00:00 | 1:00:00 |
2:00:00 | 1:00:00 | 0:00:00 |
0:00:00 | 0:00:00 | 0:00:00 |
1:00:00 | 0:45:00 | 1:00:00 |
0:00:00 | 0:00:00 | 0:00:00 |
1:00:00 | 2:00:00 | 0:30:00 |
R imported like:
# A tibble: 207 × 3
C7.1 C7.2 C7.3
<dttm> <dttm> <dttm>
1 1899-12-31 03:00:00 1899-12-31 02:00:00 1899-12-31 01:00:00
2 1899-12-31 02:00:00 1899-12-31 01:00:00 1899-12-31 00:00:00
3 1899-12-31 00:00:00 1899-12-31 00:00:00 1899-12-31 00:00:00
4 1899-12-31 01:00:00 1899-12-31 00:45:00 1899-12-31 01:00:00
5 1899-12-31 00:00:00 1899-12-31 00:00:00 1899-12-31 00:00:00
6 1899-12-31 01:00:00 1899-12-31 02:00:00 1899-12-31 00:30:00
I need to extract the hours and minutes correctly so that I can do calculations with them.
I saw this way
format(as.POSIXct(.), format = "%H:%M")
but it doesn't work for me because I need to do calculations later and be able to calculate statistical summaries.
I saw that lubridate also has duration() that allows me to calculate how many minutes in total are but first I need to get the interval and I don't know how to do it.
Any advice?