Skip to content

Create new Series

Source code

Description

This function is a simple way to convert R vectors to the Series class object. Internally, this function is a simple wrapper of as_polars_series().

Usage

pl$Series(..., values = NULL, name = NULL, dtype = NULL, nan_to_null = FALSE)

Arguments

Treated as values, name, and dtype in order. In future versions, the order of the arguments will be changed to pl$Series(name, values, dtype, …, nan_to_null) and will be ignored.
values Object to convert into a polars Series. Passed to the x argument in as_polars_series().
name A character to use as the name of the Series, or NULL (default). Passed to the name argument in as_polars_series().
dtype One of polars data type or NULL. If not NULL, that data type is used to cast the Series created from the vector to a specific data type internally.
nan_to_null If TRUE, NaN values contained in the Series are replaced to null. Using the $fill_nan() method internally.

Value

Series

See Also

  • as_polars_series()

Examples

library(polars)

# Constructing a Series by specifying name and values positionally (deprecated):
s = suppressWarnings(pl$Series(1:3, "a"))
s
#> polars Series: shape: (3,)
#> Series: 'a' [i32]
#> [
#>  1
#>  2
#>  3
#> ]
# Notice that the dtype is automatically inferred as a polars Int32:
s$dtype
#> DataType: Int32
# Constructing a Series with a specific dtype:
s2 = pl$Series(values = 1:3, name = "a", dtype = pl$Float32)
s2
#> polars Series: shape: (3,)
#> Series: 'a' [f32]
#> [
#>  1.0
#>  2.0
#>  3.0
#> ]