A data.frame data.frame() is a list with "row.names" attribute. Each element of the list must be named, and of the same length. These functions help the base data.frame classes fit in to the vctrs type system by providing constructors, coercion functions, and casting functions.

new_data_frame(x = list(), n = NULL, ..., class = NULL)

# S3 method for data.frame
vec_ptype2(x, y, ...)

# S3 method for data.frame
vec_cast(x, to, ...)

Arguments

x

A named list of equal-length vectors. The lengths are not checked; it is responsibility of the caller to make sure they are equal.

n

Number of rows. If NULL, will be computed from the length of the first element of x.

..., class

Additional arguments for creating subclasses. The "names" and "row.names" attributes override input in x and n, respectively:

  • "names" is used if provided, overriding existing names in x

  • "row.names" is used if provided, if n is provided it must be consistent.

Examples

new_data_frame(list(x = 1:10, y = 10:1))
#> x y #> 1 1 10 #> 2 2 9 #> 3 3 8 #> 4 4 7 #> 5 5 6 #> 6 6 5 #> 7 7 4 #> 8 8 3 #> 9 9 2 #> 10 10 1