Date
[1] "2020-12-08"
[1] "1974-11-01"
[1] "01.11.1974"
[1] "1909-12-07"
[1] -21940
POSIXct
[1] "2020-12-08 16:32:22 CET"
[1] "Tue Dec 8 16:32:22 2020"
[1] "2009-02-07 09:23:02 CET"
[1] "2010-06-30 17:32:10 CEST"
[1] "09:23:02"
[1] "07.02.2009"
POSIXlt
charDates <- c("05.08.1972, 03:37", "02.04.1981, 12:44")
(lDates <- strptime(charDates, format="%d.%m.%Y, %H:%M"))
[1] "1972-08-05 03:37:00 CET" "1981-04-02 12:44:00 CEST"
[1] 5 2
[1] 3 12
[1] "Saturday" "Thursday"
[1] "August" "April"
[1] "1974-11-01"
[1] "1975-11-01"
Time difference of 596 days
[1] 596
[1] "1976-06-19"
[1] "1972-08-05 03:38:00 CET" "1981-04-02 12:46:00 CEST"
Time difference of 3162.338 days
[1] "1981-04-02 12:44:00 CEST"
[1] "1972-08-05 CET" "1981-04-03 CEST"
[1] "1972-01-01 CET" "1981-01-01 CET"
[1] "2010-05-01 12:00:00 GMT" "2011-05-01 12:00:00 GMT"
[3] "2012-05-01 12:00:00 GMT" "2013-05-01 12:00:00 GMT"
[1] "1997-10-22 12:00:00 GMT" "1997-11-05 12:00:00 GMT"
[3] "1997-11-19 12:00:00 GMT" "1997-12-03 12:00:00 GMT"
secsPerDay <- 60 * 60 * 24
randDates <- ISOdate(1995, 6, 13) + sample(0:(28*secsPerDay), 100, replace=TRUE)
randWeeks <- cut(randDates, breaks="week")
summary(randWeeks)
1995-06-12 1995-06-19 1995-06-26 1995-07-03 1995-07-10
19 25 29 24 3
Package lubridate
provides many functions for efficiently and consistently handling times and dates. More packages can be found in CRAN task view Time Series.
R markdown - markdown - R code - all posts