Learn R Programming

dataPreparation (version 0.1)

diffDates: Date difference

Description

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

Usage

diffDates(dataSet, analysisDate = NULL, units = "years",
  name_separator = ".")

Arguments

dataSet

Matrix, data.frame or data.table

analysisDate

Static date (Date or POSIXct, optional)

units

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

name_separator

Separator to put between words in new column names (default to '.')

Value

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

Details

units is the same as difftime unites, but with years as a unit.

Examples

Run this code
# NOT RUN {
# First build a useful dataSet set
require(data.table)
dataSet <- data.table(ID = 1: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
dataSet <- diffDates(dataSet, analysisDate = as.Date("2016-11-14"))
# }

Run the code above in your browser using DataLab