Select all datetime columns
Description
Select all datetime columns
Usage
cs__datetime(time_unit = c("ms", "us", "ns"), time_zone = list("*", NULL))
Arguments
time_unit
|
One (or more) of the allowed time unit precision strings,
“ms” , “us” , and “ns” . Default is
to select columns with any valid timeunit.
|
time_zone
|
One of the followings. The value or each element of the vector will be
passed to the time_zone argument of the
pl$Datetime() function:
|
Value
A Polars selector
See Also
cs for the documentation on operators supported by Polars selectors.
Examples
library("polars")
chr_vec <- c("1999-07-21 05:20:16.987654", "2000-05-16 06:21:21.123456")
df <- pl$DataFrame(
tstamp_tokyo = as.POSIXlt(chr_vec, tz = "Asia/Tokyo"),
tstamp_utc = as.POSIXct(chr_vec, tz = "UTC"),
tstamp = as.POSIXct(chr_vec),
dt = as.Date(chr_vec),
)
# Select all datetime columns:
df$select(cs$datetime())
#> shape: (2, 3)
#> ┌─────────────────────────────────┬─────────────────────────────┬─────────────────────────┐
#> │ tstamp_tokyo ┆ tstamp_utc ┆ tstamp │
#> │ --- ┆ --- ┆ --- │
#> │ datetime[ns, Asia/Tokyo] ┆ datetime[ms, UTC] ┆ datetime[ms] │
#> ╞═════════════════════════════════╪═════════════════════════════╪═════════════════════════╡
#> │ 1999-07-21 05:20:16.987653999 … ┆ 1999-07-21 05:20:16.987 UTC ┆ 1999-07-21 05:20:16.987 │
#> │ 2000-05-16 06:21:21.123456 JST ┆ 2000-05-16 06:21:21.123 UTC ┆ 2000-05-16 06:21:21.123 │
#> └─────────────────────────────────┴─────────────────────────────┴─────────────────────────┘
#> shape: (2, 2)
#> ┌─────────────────────────────┬─────────────────────────┐
#> │ tstamp_utc ┆ tstamp │
#> │ --- ┆ --- │
#> │ datetime[ms, UTC] ┆ datetime[ms] │
#> ╞═════════════════════════════╪═════════════════════════╡
#> │ 1999-07-21 05:20:16.987 UTC ┆ 1999-07-21 05:20:16.987 │
#> │ 2000-05-16 06:21:21.123 UTC ┆ 2000-05-16 06:21:21.123 │
#> └─────────────────────────────┴─────────────────────────┘
#> shape: (2, 2)
#> ┌─────────────────────────────────┬─────────────────────────────┐
#> │ tstamp_tokyo ┆ tstamp_utc │
#> │ --- ┆ --- │
#> │ datetime[ns, Asia/Tokyo] ┆ datetime[ms, UTC] │
#> ╞═════════════════════════════════╪═════════════════════════════╡
#> │ 1999-07-21 05:20:16.987653999 … ┆ 1999-07-21 05:20:16.987 UTC │
#> │ 2000-05-16 06:21:21.123456 JST ┆ 2000-05-16 06:21:21.123 UTC │
#> └─────────────────────────────────┴─────────────────────────────┘
# Select all datetime columns that have a specific timezone:
df$select(cs$datetime(time_zone = "UTC"))
#> shape: (2, 1)
#> ┌─────────────────────────────┐
#> │ tstamp_utc │
#> │ --- │
#> │ datetime[ms, UTC] │
#> ╞═════════════════════════════╡
#> │ 1999-07-21 05:20:16.987 UTC │
#> │ 2000-05-16 06:21:21.123 UTC │
#> └─────────────────────────────┘
#> shape: (2, 1)
#> ┌─────────────────────────┐
#> │ tstamp │
#> │ --- │
#> │ datetime[ms] │
#> ╞═════════════════════════╡
#> │ 1999-07-21 05:20:16.987 │
#> │ 2000-05-16 06:21:21.123 │
#> └─────────────────────────┘
#> shape: (2, 1)
#> ┌────────────┐
#> │ dt │
#> │ --- │
#> │ date │
#> ╞════════════╡
#> │ 1999-07-21 │
#> │ 2000-05-16 │
#> └────────────┘