todate: Convert to Date.

Description Usage Arguments Value Examples

Description

Convert a vector to date. By default, returns vector unchanged if new NAs would be created. You can send non-dates in loops (or otherwise) and they won't be affected. Can be useful for checking if something is a date.

Usage

1
2
3
4
todate(x, do.time = FALSE, do.excel = TRUE, na.vals = bc::nastrings,
  already.clean.vector = FALSE, verbose = TRUE,
  do.na = c("return-unchanged", "warning", "stop", "return-na"),
  min.acceptable.date = "1-1-1900", max.acceptable.date = "12-31-2100")

Arguments

x

Vector to convert.

do.time

Allow processing to time values.

do.excel

Allow conversion of excel date integers.

already.clean.vector

Sometimes in multi-step data operations clean.vector will have already been called.

verbose

Print useful information via cat.

do.na

What to do in case new NAs are created during conversion. If all NAs, the vector will be returned unchanged. Otherwise, this argument determines behavior: return-unchnaged returns the vector unchanged. warning returns new NAs with a warning. stop throws an error. return-na prints a message with cat which can be turned off with verbose = FALSE.

min.acceptable.date

Set to NULL to ignore. Sometimes numbers are assumed to be excel-formatted. One way to prevent this is to set min/max acceptable dates to help the conversion know if something is a meaningful data or not.

max.acceptable.date

Set to NULL to ignore. Sometimes numbers are assumed to be excel-formatted. One way to prevent this is to set min/max acceptable dates to help the conversion know if something is a meaningful data or not.

Value

Processed vector.

Examples

1
2
3
4
5
todate( c( '12/3/14', 'Hello'), do.na = 'return-na' )
todate( c( '12/3/14', 'Hello') )
todate( c( "2018-10-20", "2018-10-20", "2018-10-20", "2018-10-20" ), verbose = FALSE )
todate( c( "6/12/2015 20:45:00", "4/4/2015 22:20:00" , "4/11/2016 23:24:00", "9/29/2016 1:10:00" ), do.time = TRUE )
todate( 43393.5138888889, do.time = TRUE ) # this is 2018-10-20 12:20:00 in Excel.

superchordate/bc documentation built on June 20, 2019, 4:05 p.m.