Skip to content

Select all time columns

Description

Select all time columns

Usage

cs__time()

Value

A Polars selector

See Also

cs for the documentation on operators supported by Polars selectors.

Examples

library("polars")


df <- pl$DataFrame(
  dtm = as.POSIXct(c("2001-5-7 10:25", "2031-12-31 00:30")),
  dt = as.Date(c("1999-12-31", "2024-8-9")),
  tm = hms::parse_hms(c("0:0:0", "23:59:59"))
)

# Select time columns:
df$select(cs$time())
#> shape: (2, 1)
#> ┌──────────┐
#> │ tm       │
#> │ ---      │
#> │ time     │
#> ╞══════════╡
#> │ 00:00:00 │
#> │ 23:59:59 │
#> └──────────┘
# Select all columns except for those that are time:
df$select(!cs$time())
#> shape: (2, 2)
#> ┌─────────────────────┬────────────┐
#> │ dtm                 ┆ dt         │
#> │ ---                 ┆ ---        │
#> │ datetime[ms]        ┆ date       │
#> ╞═════════════════════╪════════════╡
#> │ 2001-05-07 10:25:00 ┆ 1999-12-31 │
#> │ 2031-12-31 00:30:00 ┆ 2024-08-09 │
#> └─────────────────────┴────────────┘