nameColumns: This function, changes the column names of the given table...

View source: R/rutils.R

nameColumnsR Documentation

This function, changes the column names of the given table (data.frame) and checks for the column classes

Description

This function, changes the column names of the given table (data.frame) and checks for the column classes

Usage

nameColumns(dataset, columns, classes = NULL, convert = T)

Arguments

dataset

A table(data.frame) on which the column names is going to change

columns

A named list of characters indicating which names should change to what. List values should be a subset of original column names and list names are names to which the original column names should change

classes

a named list of characters inducating the required classes of each column. List names should be the new column names and values are classes required for each column

convert

A boolean indicating if columns should be coerced to the required class. Function returns error is coercing is not possible. Defaulted is TRUE. If FALSE, the function verifies the column classes and returns error if don't match.

Value

A table(data.frame) same class as the input table dataset

Examples

Data = data.frame(x = c(1,2,3), y = c('10', '20', '30'), z = c('One', 'two', 'three'), stringsAsFactors = F)
Data %>% nameColumns(columns = list(XX = 'x', YY = 'y', ZZ = 'z'), classes = list(XX = 'integer', YY = 'numeric'))


genpack/gener documentation built on March 14, 2023, 9:52 a.m.