dfTemplate: Create a data frame from scratch or based on one or two data...

View source: R/dfTemplate.R

dfTemplateR Documentation

Create a data frame from scratch or based on one or two data frames

Description

This function handles the creation of data frames based on intuitive parameters. It was originally designed to make row binding easier when columns differs among data frame by creating data frames with the same columns.

Usage

dfTemplate(cols, nrows = 1, col_classes = NULL, fill = NA)

dfTemplateMatch(x, y, yonly = FALSE, order = FALSE, ...)

Arguments

cols

either a number of column or a vector of character used as columns names of the data frame to be returned.

nrows

row number.

col_classes

vector of column classes for the desired data frame. By default, the class is determined by fill.

fill

character or number used to fill out the columns. Default is NA.

x

a data frame.

y

a data frame or a vector of strings use to specifies column names to be included in the data frame.

yonly

a logical. Should only y (or the names(y)) be used for the data frame to be returned? Default is set to FALSE meaning that both the names of x and the names of y are used.

order

a logical. Should column of the output data frame be ordered according to the template. Not that if there are more columns in x that are not in y, then if order = TRUE column of y will be added first (on the left of the output data frame).

...

further arguments to be passed to dfTemplate().

Value

Returns a data frame with the desired characteristics.

Functions

  • dfTemplateMatch(): Returns a data frame that includes all columns specifies in y.

References

https://insileco.github.io/2019/02/03/creating-empty-data-frames-with-dftemplate-and-dftemplatematch/

Examples

dfTemplate(5, 2)
dfTemplate(5, 2, col_classes = "character")
dfA <- data.frame(col1 = c(1, 2), col2 = LETTERS[1:2])
dfB <- data.frame(col4 = c(1, 2), col2 = LETTERS[1:2])
dfTemplateMatch(dfA, c("col4", "col2"))
dfTemplateMatch(dfA, c("col4", "col2"), yonly = TRUE)
dfTemplateMatch(dfA, dfB, yonly = TRUE, order = TRUE)

inSileco/letiRmisc documentation built on Sept. 16, 2022, 2:19 p.m.