Learn R Programming

SpatioTemporal (version 1.1.7)

convertCharToDate: Convert Character to Dates

Description

Attempts to convert input vector to Date, if that fails tries to convert to double. If conversion induces NA the function returns NULL indicating a failure.

Usage

convertCharToDate(x)

Arguments

x

character vector to convert to dates

Value

a vector of dates, or of doubles or NULL.

See Also

Other utility functions: defaultList

Examples

Run this code
# NOT RUN {
##a vector of dates is returned as is
convertCharToDate( seq(as.Date("2012-01-01"),as.Date("2012-01-31"),by=5) )

##if given as chracter vectors Date is returned
convertCharToDate( c("2012-01-01","2012-01-05","2012-01-10","2012-01-12") )

##double is returned as is
convertCharToDate( rnorm(5) )

##other things result in NULL
convertCharToDate( c("a","b","c") )
convertCharToDate( c("2012-01-01", "2012-01-05", "a", "2012-01-12") )
convertCharToDate( c(1,2,3,"d") )
# }

Run the code above in your browser using DataLab