generate_date_diffs {dataPreparation}R Documentation

Date difference

Description

Perform the differences between all dates of the data_set set and optionally with a static date.

Usage

generate_date_diffs(
  data_set,
  cols = "auto",
  analysis_date = NULL,
  units = "years",
  drop = FALSE,
  verbose = TRUE,
  ...
)

Arguments

data_set

Matrix, data.frame or data.table

cols

List of date column(s) name(s) of data_set to comute difference on. To transform all dates, set it to "auto". (character, default to "auto")

analysis_date

Static date (Date or POSIXct, optional)

units

Unit of difference between too dates (string, default to 'years')

drop

Should cols be dropped after generation (logical, default to FALSE)

verbose

should the function log (logical, default to TRUE)

...

Other arguments such as name_separator to separate words in new columns names (character, default to ".")

Details

units is the same as difftime units, but with one more possiblity: years.

Value

data_set (as a data.table) with more columns. A numeric column has been added for every couple of Dates. The result is in years.

Examples

# First build a useful data_set set
require(data.table)
data_set <- data.table(ID = seq_len(100),
                  date1 = seq(from = as.Date("2010-01-01"),
                              to = as.Date("2015-01-01"),
                              length.out = 100),
                  date2 = seq(from = as.Date("1910-01-01"),
                              to = as.Date("2000-01-01"),
                              length.out = 100)
                  )

# Now let's compute
data_set <- generate_date_diffs(data_set, cols = "auto", analysis_date = as.Date("2016-11-14"))

[Package dataPreparation version 1.0.4 Index]