timediff: timediff() function

Description Usage Arguments Details Value Examples

View source: R/timediff.R

Description

This function calculates the time difference between two dates. It will return the time difference as a number in years rounded to two decimal places.

Usage

1
timediff(start_date, end_date, na.rm = TRUE)

Arguments

start_date

The date you want to calculate the time difference from this date

end_date

The date you want to calculate the time difference to this date

na.rm

Remove NA values before calculation

Details

Inputs need to be in date format. You may use as.Date() or ymd() from the lubridate package to change the character or number into date format. If your inputs are not dates, the function will return an error message and tell you what format you have entered. So you can make adjustments accordingly.

Value

A number in the unit of years rounded to two decimal places

Examples

1
2
timediff(as.Date("2021-10-01"), as.Date("2021-10-04"))
timediff(datateachr::vancouver_trees$date_planted, lubridate::ymd("2021-10-04"))

stat545ubc-2021/timediff_package documentation built on Dec. 23, 2021, 5:26 a.m.