ToDate: String To Date

Description Usage Arguments Examples

View source: R/format-text.R

Description

This function converts a set of character strings to date format using the specified lubridate method

Usage

1
ToDate(data, fields = NA, method = "ymd", debug = FALSE)

Arguments

data

Data frame or character string or vector to be manipulated

fields

Character vector of fields; not necessary if passing a vector

method

Which lubridate method to use for parsing; defaults to ymd

debug

If TRUE, print debug output

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
ToDate(c("3-21-1911", "8-8-2008"), method="mdy")

my.dates <- data.frame(x1 = c("1911-03-21", "2008-08-08"),
                       x2 = c("2009-01-01", "3001-01-01"),
                       x3 = c("1805-12-31", "1555-06-12"),
                       stringsAsFactors = FALSE)
# All three columns are chr
str(my.dates)

my.dates2 <- ToDate(my.dates, fields=c("x1", "x3"))
# The first and third column are now Date, but the second is still chr
str(my.dates2)

my.dates3 <- ToDate(my.dates, fields=1:3)
# All three columns are now Date
str(my.dates3)

phively/wranglR documentation built on April 11, 2020, 5:12 a.m.