Description Usage Arguments Value Author(s) Examples
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)
1 |
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 |
a dataframe including day, year, quarter, month, year.quarter,
Daniel Gardiner (daniel.gardiner@phe.gov.uk)
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.