convert.all.dates: Convert all date columns of a data.frame to Date vectors.

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/convert_dates.R

Description

This function identifies all date columns in a data frame and converts them to vectors of Date objects. Optionally, unknown dates (e.g. coded as '1900-01-01') can be converted to NA.

Usage

1
2
3
4
convert.all.dates(dat, .format = "%Y-%m-%d",
  convert.unknown.date.to.na = FALSE, unknown.date.string = NULL,
  partial.date.handling = "skip", partial.date.string = "Unknown",
  silent = FALSE)

Arguments

dat

data frame to convert dates

.format

format of the dates (default: '%Y-%m-%d')

convert.unknown.date.to.na

flag for conversion of unknown dates

unknown.date.string

string specifying the coding of unknown dates

partial.date.handling

how to handle columns containing entries that cannot be converted (default: skip; see Details)

partial.date.string

string used for unknown data components (e.g. 'Unknown' or '–')

silent

hide verbose output

Details

partial.date.handling: By default, potential data columns containing entries that cannot be converted are skipped (option 'skip'). With 'force.conversion' fields incompatible with the date format are converted to NA. 'fill.partial.dates' keeps the orginal column untouched and adds a new column to the data frame with the name <colname>.partial.dates.processed in which partial are filled using fill.partial.date (e.g. Unknown.01.2013 -> 15.01.2013). With 'fill.partial.dates.and.keep.original' partial dates are processed directly and the original data is copied to <colname>.original.

Value

Date frame with date columns converted.

Author(s)

Pascal Benkert

See Also

fill.partial.date

Examples

1
2
3
4
5
6
convert.all.dates(data.frame(date=c("2014-01-Unknown", "1900-01-01")),
partial.date.handling="fill.partial.dates", convert.unknown.date.to.na = TRUE,
unknown.date.string="1900-01-01")
##              date date.partial.dates.processed
##1  2014-01-Unknown                   2014-01-15
##2       1900-01-01                         <NA>

SwissClinicalTrialOrganisation/DM_secuTrial_R documentation built on May 21, 2019, 10:16 a.m.