Date_Shift {Colossus} | R Documentation |
Automates creating a date difference column
Description
Date_Shift
generates a new dataframe with a column containing time difference in a given unit
Usage
Date_Shift(df, dcol0, dcol1, col_name, units = "days")
Arguments
df |
a data.table containing the columns of interest |
dcol0 |
list of starting month, day, and year |
dcol1 |
list of ending month, day, and year |
col_name |
vector of new column names |
units |
time unit to use |
Value
returns the updated dataframe
See Also
Other Data Cleaning Functions:
Check_Dupe_Columns()
,
Check_Trunc()
,
Check_Verbose()
,
Correct_Formula_Order()
,
Def_Control()
,
Def_Control_Guess()
,
Def_model_control()
,
Def_modelform_fix()
,
Joint_Multiple_Events()
,
Replace_Missing()
,
Time_Since()
,
factorize()
,
factorize_par()
,
gen_time_dep()
,
interact_them()
Examples
library(data.table)
m0 <- c(1, 1, 2, 2)
m1 <- c(2, 2, 3, 3)
d0 <- c(1, 2, 3, 4)
d1 <- c(6, 7, 8, 9)
y0 <- c(1990, 1991, 1997, 1998)
y1 <- c(2001, 2003, 2005, 2006)
df <- data.table::data.table("m0" = m0, "m1" = m1, "d0" = d0, "d1" = d1, "y0" = y0, "y1" = y1)
df <- Date_Shift(df, c("m0", "d0", "y0"), c("m1", "d1", "y1"), "date_since")
[Package Colossus version 1.1.4.2 Index]