Skip to content

Create a new polars DataFrame

Source code

Description

Create a new polars DataFrame

Usage

pl$DataFrame(..., make_names_unique = TRUE, schema = NULL)

Arguments

One of the following:
  • mixed vectors and/or Series of equal length
  • a list of mixed vectors and Series of equal length (Deprecated, please use as_polars_df() instead).
Columns will be named as of named arguments or alternatively by names of Series or given a placeholder name.
make_names_unique If TRUE (default), any duplicated names will be prefixed a running number.
schema A named list that will be used to convert a variable to a specific DataType. Same as schema_overrides of as_polars_df().

Value

DataFrame

See Also

  • as_polars_df()

Examples

library("polars")

pl$DataFrame(
  a = c(1, 2, 3, 4, 5),
  b = 1:5,
  c = letters[1:5],
  d = list(1:1, 1:2, 1:3, 1:4, 1:5)
) # directly from vectors
#> shape: (5, 4)
#> ┌─────┬─────┬─────┬─────────────┐
#> │ a   ┆ b   ┆ c   ┆ d           │
#> │ --- ┆ --- ┆ --- ┆ ---         │
#> │ f64 ┆ i32 ┆ str ┆ list[i32]   │
#> ╞═════╪═════╪═════╪═════════════╡
#> │ 1.0 ┆ 1   ┆ a   ┆ [1]         │
#> │ 2.0 ┆ 2   ┆ b   ┆ [1, 2]      │
#> │ 3.0 ┆ 3   ┆ c   ┆ [1, 2, 3]   │
#> │ 4.0 ┆ 4   ┆ d   ┆ [1, 2, … 4] │
#> │ 5.0 ┆ 5   ┆ e   ┆ [1, 2, … 5] │
#> └─────┴─────┴─────┴─────────────┘