split_date: Splits/parses dates

Description Usage Arguments Examples

View source: R/dates.R

Description

Separates dates from a vector or a data.frame

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
split_date(
  x,
  year = "year",
  month = "month",
  day = "day",
  dates_to_row = FALSE
)

parse_date(
  x,
  cols,
  year = "year",
  month = "month",
  day = "day",
  sep = "_",
  keep = FALSE
)

Arguments

x

A vector or data.frame

year

Name for year column or column suffix

month

Name for month column or column suffix

day

Name for day column or column suffix

dates_to_row

Logical, if 'TRUE', adds dates to the row names

cols

A character vector of the columns to parse into dates

sep

String to use to separate new columns

keep

Logical, if 'TRUE' the original date column is kept

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
x <- c("2010-01-12", "2020-09-30", "1999-12-31")
split_date(as.Date(x))

xx <- data.frame(
  x1 = 1:3,
  x2 = runif(3),
  date1 = as.Date(c("1950-10-05", "2020-04-29", "1992-12-17")),
  x3 = letters[1:3],
  date2 = as.Date(c("2010-01-12", "2020-09-30", "1999-12-31")))
parse_date(xx, c("date1", "date2"))

jmbarbone/dirtyr documentation built on Sept. 23, 2020, 4:05 a.m.