View source: R/rates_of_change.R
difference | R Documentation |
Calculate a difference between two numbers or times. For numeric objects, the difference is calculated as x2 - x1
. For time objects (i.e., DateTimeClasses
or Dates
), the difference is calculated using difftime
. A function can be supplied to process outputs; e.g. abs
, or numeric
for difftime
objects.
difference(x2, x1, f = NULL, ...)
x2 |
A number, |
x1 |
A number, |
f |
A function to process outputs. |
... |
Other arguments passed to |
The function returns the difference between two numbers or times.
Edward Lavender
#### Example (1) Numeric difference difference(1, 2) #### Example (2) Numeric difference with post processing difference(1, 2, f = abs) #### Example (3) Difference with times difference(as.POSIXct("2016-01-05"), as.POSIXct("2016-01-01")) #### Example (4) Difference with times and units specified difference(as.POSIXct("2016-01-05"), as.POSIXct("2016-01-01"), units = "mins") #### Example (5) Difference with times, specified units and post-processing difference(as.POSIXct("2016-01-05"), as.POSIXct("2016-01-01"), units = "mins", f = as.numeric)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.