Format a date object the same as base::format() but return a numerical value when able instead of always returning a character string. Users dictate what is returned by the same format argument that is used in base::format().

f_date(x, format = c("%m", "%Y"), factor = FALSE)

Arguments

x

A vector of dates with class POSIXct, POSIXt, or Date.

format

A character value specifying the format you want the output to be in. See base::strptime() for options.

factor

A logical specifying if you want a factor to be returned. The factor is ALWAYS limited to the levels that are available. The default behavior is to NOT return a factor. Thus, this must be invoked.

Value

A vector the same length as the input vector.

Author

Kelli F. Johnson