Extract ordinal day from underlying Date representation
Description
Returns the day of year starting from 1. The return value ranges from 1 to 366 (the last day of year differs across years).
Usage
<Expr>$dt$ordinal_day()
Value
A polars expression
Examples
library("polars")
df <- pl$select(
date = pl$date_range(
as.Date("2020-12-25"),
as.Date("2021-1-05"),
interval = "1d"
)
)
df$with_columns(
ordinal_day = pl$col("date")$dt$ordinal_day()
)
#> shape: (12, 2)
#> ┌────────────┬─────────────┐
#> │ date ┆ ordinal_day │
#> │ --- ┆ --- │
#> │ date ┆ i16 │
#> ╞════════════╪═════════════╡
#> │ 2020-12-25 ┆ 360 │
#> │ 2020-12-26 ┆ 361 │
#> │ 2020-12-27 ┆ 362 │
#> │ 2020-12-28 ┆ 363 │
#> │ 2020-12-29 ┆ 364 │
#> │ … ┆ … │
#> │ 2021-01-01 ┆ 1 │
#> │ 2021-01-02 ┆ 2 │
#> │ 2021-01-03 ┆ 3 │
#> │ 2021-01-04 ┆ 4 │
#> │ 2021-01-05 ┆ 5 │
#> └────────────┴─────────────┘