get_dates: Get dates

Description Usage Arguments Value Author(s) Examples

View source: R/get_dates.R

Description

This function converts a vector of dates into data.frame where each column is a useful date type (year, quarter, month, year.quarter, year.month, iso.year, iso.week, iso.year.week)

Usage

1
get_dates(x, factor.start = NULL, factor.end = NULL)

Arguments

x

a vector of dates in date format

factor.start

a character in format "yyyy-mm-dd" specifying the first level of the factor

factor.end

a character in format "yyyy-mm-dd" specifying the last level of the factor

Value

a dataframe including day, year, quarter, month, year.quarter,

Author(s)

Daniel Gardiner (daniel.gardiner@phe.gov.uk)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# set dummy data

set.seed(2)

data = data.frame(date = sample(seq(as.Date("2017-03-01"), as.Date("2017-08-01"), 1), 20, replace = TRUE),
                  sex = sample(c("Female", "Male"), 20, replace = TRUE))


# apply function

get_dates(data$date)

# append results of function to original data.frame

cbind(data, get_dates(data$date))

# apply function, specifying the output should be a factor (providing a start and end date)

get_dates(data$date, factor.start = "2017-01-01", factor.end = "2017-08-31")

# tabulate number of cases by year.month (this includes all year.months over the period defined by the factor.start anf factor.end arguments)

table(get_dates(data$date, factor.start = "2017-01-01", factor.end = "2017-08-31")$year.month)

DanielGardiner/EpiFunc documentation built on July 25, 2019, 10:53 p.m.