# EXAMPLES FOR date3to1
data0 <- data.frame(y=c(NA, -1, 2001:2009),
m=c(1:2, -1, NA, 13, 2, 12, 6:9),
d=c(0, 0:6, NA, -1, 32) )
head(data0)
# combine and convert to date
# return as data frame
date3to1(data0)
# combine and convert to date
# return as vector
date3to1(data0, as.vector = TRUE) #eg. 2004-02-04
# combine and convert to date in the format DD_MM_YYYY
date3to1(data0, out.format = "%d_%m_%Y") #eg. 04_02_1974
# combine and convert to date in the format MM_DD_YY
date3to1(data0, out.format = "%m_%d_%y") #eg. 02_04_74
# combine and convert to date in the various date formats
date3to1(data0, out.format = "%B %d, %y") #eg. February 04, 74
date3to1(data0, out.format = "%a, %b %d, %Y") #eg. Mon, Feb 04, 1974
date3to1(data0, out.format = "%A, %B %d, %Y") #eg. Monday, February 04, 1974
date3to1(data0, out.format = "Day %j in Year %Y") #eg. Day 035 in Year 1974
date3to1(data0, out.format = "Week %U in %Y") #eg. Week 05 in 1974
date3to1(data0, out.format = "Numeric month %m in Year %Y") #eg. Numeric month 02 in Year 1974
# EXAMPLES FOR date1to3
data1 <- data.frame(Full.Dates =
c("2023-02-14",NA,NA,
"2002-12-04","1974-08-04",
"2008-11-10"))
head(data1)
# split date with default settings
# return as data frame with columns
# for day(d), month(m) and year(Y)
date1to3(data1)
# split date in the format and only return year in YYYY
date1to3(data1, out.cols = "%Y") #eg. 2002, 2023
# split date in the format and only return month in m
date1to3(data1, out.cols = "%m") #eg. 02, 12, 08
# split date in the format and return multiple date formats colums
date1to3(data1, out.cols = c("%B","%d") )
date1to3(data1, out.cols = c("%a","%b","%y") )
date1to3(data1, out.cols = c("%A","%B","%Y","%y") )
date1to3(data1, out.cols = c("%j","%Y","%y","%m") )
date1to3(data1, out.cols = c("%U","%Y","%y","%x") )
date1to3(data1, out.cols = c("%m","%Y","%y","%C") )
Run the code above in your browser using DataLab