am_expand_date {africamonitor}R Documentation

Generate Temporal Identifiers from a Date Column

Description

This function expands a date column and generates additional temporal identifiers from it (such as the year, month, quarter, fiscal year etc.).

Usage

am_expand_date(
  x,
  gen = c("Year", "Quarter", "Month"),
  origin = "1899-12-30",
  keep.date = TRUE,
  remove.missing.date = TRUE,
  sort = TRUE,
  as.factor = TRUE,
  name = "Date",
  ...
)

Arguments

x

either a vector of class 'Date', or coercible to date using as.Date, or a data frame / list containing with a date-column called name.

gen

character. A vector of identifiers to generate from x. The possible identifiers are found in .AMT.

origin

character / Date. Passed to as.Date: for converting numeric x to date.

keep.date

logical. TRUE will keep the date variable in the resulting dataset, FALSE will remove the date variable in favor of the generated identifiers.

remove.missing.date

logical. TRUE will remove missing values in x. If x is a dataset, rows missing the date variable will be removed.

sort

logical. TRUE will sort the data by the date column.

as.factor

TRUE will generate quarters, fiscal years and months ('Quarter', 'FY', 'QFY', 'Month') as factor variables. It is also possible to use as.factor = "ordered" to generate ordered factors. FALSE will generate fiscal years as character and quarters and months as integer variables.

name

character. The name of the date variable to expand.

...

not used.

Value

A data.table containing the computed identifiers as columns. See Examples.

See Also

am_as_date, africamonitor

Examples

# First a basic example
x <- seq.Date(as.Date("1999-01-01"), as.Date("2000-01-01"), by = "month")
am_expand_date(x)
am_expand_date(x, gen = .AMT[-1L], keep.date = FALSE)

# Now using the API
am_expand_date(am_data("KEN"))

# Same thing
am_data("KEN", expand.date = TRUE)



[Package africamonitor version 0.2.4 Index]