Learn R Programming

exceldata (version 0.1.1.3)

addFactorVariables: Create factor variables from data dictionary

Description

This function will replace the code and category variables with factors based on the factor levels provided in the data dictionary. The original variables are retained with the suffix '_orig'

Usage

addFactorVariables(data, dictionary, keepOriginal = TRUE)

Value

A data frame with the updated factor variables

Arguments

data

A data frame returned by readExcelData

dictionary

A data frame returned by readDataDict

keepOriginal

Boolean indicating if the original character variables should be kept, default is TRUE with _original appended to variable names

Examples

Run this code
if (FALSE) {
exampleDataFile <- system.file("extdata", "exampleData.xlsx", package = "exceldata")
dictionary <- readDataDict(exampleDataFile, dictionarySheet = 'DataDictionary')
data <- readExcelData(exampleDataFile,dictionary,dataSheet='DataEntry')
factorData <- addFactorVariables(data,dictionary,keepOriginal = TRUE)
}

Run the code above in your browser using DataLab