dumbify: dumbify

Description Usage Arguments Details Value Author(s) Examples

Description

function to automatically rename columns in an input data frame or data table within a function so that columns needed for the analysis can be easily accessed.

Usage

1
dumbify(in_data, in_names, out_names = NULL)

Arguments

in_data

data.frame or data.table

in_names

character array containing names of the variables containing the names of the columns of in_data needed for the analysis

out_names

character array containing names to which the columns on selected in in_names should be changed to needed for the analysis. If NULL, out_names are reset to the names of the names of the variables passed as in_names (see examples), Default: NULL

Details

To avoid loss of data, the function checks beforehand to see if any columns in in_data are named as one of out_names. In that case, the names of those columns are replaced as "!!!!"

Value

a copy of in_data with replaced column names

Author(s)

Lorenzo Busetto, phD (2017) lbusett@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Not run: 
in_data = iris
dumb_addcol <- function(in_data, ADD_1_VAR, ADD_2_VAR) {
  out_data <- in_data %>%
     dumbify(in_names = c(ADD_1_VAR, ADD_2_VAR)) %>%
     dplyr::mutate(sum = ADD_1_VAR + ADD_2_VAR) %>%
     undumbify(c(ADD_1_VAR, ADD_2_VAR))
 out_data
 }
 ADD_1_VAR   <- "Petal.Length"
 ADD_2_VAR   <- "Petal.Width"
 out <- dumb_addcol(in_data, ADD_1_VAR, ADD_2_VAR)
 head(out)
 ADD_2_VAR   <- "Sepal.Length"
 out <- dumb_addcol(in_data, ADD_1_VAR, ADD_2_VAR)
 head(out)

## End(Not run)

lbusett/dumpify documentation built on May 3, 2019, 4:07 p.m.