init_new_cols: Initialize new columns of the correct length

View source: R/table_recipe_utils.R

init_new_colsR Documentation

Initialize new columns of the correct length

Description

Initialize new columns of the correct length

Usage

init_new_cols(
  n,
  colnames = names(colclasses),
  colclasses = setNames(rep(NA, length(colnames)), colnames)
)

Arguments

n

numeric(1). The length (number of rows) to use when initializing.

colnames

character. Vector of column names to use. Can be omitted if colclasses is specified.

colclasses

named character. Optional. Names must be identical to colnames if specified, values are classes such that as(NA, .) will succeed. Defaults to NA for each column, indicating character columns.

Value

A data.frame with the new columns and n rows.

Examples


init_new_cols(5, c("col1", "col2"))

init_new_cols(5, colclasses = c(col1 = NA, col2 = "integer"))


Roche/respectables documentation built on Oct. 2, 2024, 8:57 p.m.