setLabelToVariable: set label to each column of data.frame based on dictionnaty

Description Usage Arguments Value Examples

Description

add a label as attribute (var_label) to each column of data.frame based on dictionnary. This label will be used during the reporting function.

Usage

1
setLabelToVariable(data, varLabel, varIndex = 1, labelIndex = 2)

Arguments

data

the data.frame witch nedd to be labelised

varLabel

a data.frame with two columns : 1) the variable colname, 2) the clean label to display

varIndex

a numeric vector of length one, containing the index if the variable label column.

labelIndex

a numeric vector of length one, containing the index if the variable label column.

Value

a data.frame with the var_label attribute

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
data(mtcars)
label <- data.frame(VARIABLE = colnames(mtcars),
                    LABEL = c("Miles/(US) gallon",
                              "Number of cylinders",
                              "Displacement (cu.in.)",
                              "Gross horsepower",
                              "Rear axle ratio",
                              "Weight (1000 lbs)",
                              "1/4 mile time",
                              "Engine (0 = V-shaped, 1 = straight)",
                              "Transmission (0 = automatic, 1 = manual)",
                              "Number of forward gears",
                              "Number of carburetors"),
                    stringsAsFactors = FALSE)

labeled_df <- setLabelToVariable(mtcars, label)
lapply(labeled_df, function(x) attributes(x)$`var_label`)

rgriffier/statsBordeaux documentation built on Aug. 11, 2021, 9:59 a.m.