RApiDatetime (version 0.0.4)

asDatePOSIXct: Conversion from POSIXct to Date

Description

Conversion from POSIXct to Date

Usage

asDatePOSIXct(x, tz = "")

Arguments

x

A POSIXct vector

tz

An optional timezone string

Value

A vector of Date objects

Details

This function provides a direct conversion from POSIXct to Date. As of R-3.5.1, conversion from POSIXct to Date creates an intermediate POSIXlt object. This intermediate POSIXlt object uses a non-trivial amount of memory. The direct conversion is more memory efficient, and therefore approximately twice as fast as the current solution in base R.

Examples

Run this code
# NOT RUN {
p <- .POSIXct(1540181413, "America/Chicago")
as.Date(p)                     # Using UTC timezone
as.Date(p, "America/Chicago")  # Using local timezone
asDatePOSIXct(p)               # Direct, using local timezone
# }

Run the code above in your browser using DataLab