.difftime(xx, units) # generally for internal use difftime(time1, time2, tz, units = c("auto", "secs", "mins", "hours", "days", "weeks"))## S3 method for class 'difftime': print(x, digits = getOption("digits"), ...) ## S3 method for class 'difftime': [(x, ..., drop = TRUE) ## S3 method for class 'difftime': c(..., recursive = FALSE) ## S3 method for class 'difftime': diff(x, lag = 1L, differences = 1L)
xx | an S object. |
time1, time2 | an S object that is inherited from or can be converted to POSIXt, such as POSIXct or POSIXlt objects or date-time strings. |
tz | a character string representing the time zone, such as "GMT". |
units | a character string from "auto", "secs", "mins", "hours", "days", and "weeks". |
format | a character string representing the time format for tim. |
x | a difftime object. |
digits | the maximum number of (significant) digits to print. |
drop | a logical flag passed to operator [. |
lag | a positive integer, the spacing of the entries to difference |
differences | a positive integer, the number of iterations of differencing |
... | additional arguments. |
.difftime | returns a difftime object with specified units. |
difftime | returns a difftime object representing the time difference between time1 and time2. |
print.difftime | returns the original object x, with the invisible flag set to prevent reprinting. |
[.difftime | returns a difftime object formed by extracting the relevant subset. |
c.difftime | returns a difftime object formed by the concatenation of all of its inputs (except recursive, which is ignored). If the units of all of the difftime inputs are the same, then it is the units of the output. If the units differ or if no inputs are difftime objects, then the output units are "secs". |
diff.difftime | returns a difftime object with the units of x and values diff(as.numeric(x), lag, differences) |
sunrise <- as.POSIXct(c("2019-03-18 07:14:17", "2019-03-19 07:12:12", "2019-03-20 07:10:08", "2019-03-21 07:08:03")) sunset <- as.POSIXct(c("2019-03-18 19:19:59", "2019-03-19 19:21:28", "2019-03-20 19:22:58", "2019-03-21 19:24:27")) sunset-sunrise # units chosen automatically: hours difftime(sunset, sunrise, units="mins") # user control of units (ds <- diff(sunset)) # units chosen automatically: days units(ds) <- "hours" # change units to hours ds diff(difftime(sunset, sunrise, units="secs")) # change in day lengths, in seconds(x <- as.difftime(c("0:20", "1:05", "0:35"), format="%H:%M")) x[c(3,1)] c(x[3], x[1])