Learn R Programming

dataPreparation (version 0.4.3)

sameShape: Give same shape

Description

Transform dataSet into the same shape as referenceSet. Espacially this function will be usefull to make your test set have the same shape as your train set.

Usage

sameShape(dataSet, referenceSet, verbose = TRUE)

Arguments

dataSet

Matrix, data.frame or data.table to transform

referenceSet

Matrix, data.frame or data.table

verbose

Should the algorithm talk? (logical, default to TRUE)

Value

Return dataSet transformed in order to make it have the same shape as referenceSet

Details

This function will make sure that dataSet and referenceSet

  • have the same class

  • have exactly the same columns

  • have columns with exactly the same class

  • have factor factor with exactly the same levels

You should always use this function before applying your model on a new data set to make sure that everything will go smoothly. But if this function change a lot of stuff you should have a look to your preparation process, there might be something wrong.

Examples

Run this code
# NOT RUN {
# Build a train and a test
data("messy_adult")
data("adult")
train <- messy_adult
test <- adult # So test will have missing columns

# Prepare them
train <- prepareSet(train, verbose = FALSE, key = "country")
test <- prepareSet(test, verbose = FALSE, key = "country")

# Give them the same shape
test <- sameShape(test, train)
# As one can see in log, a lot of small change had to be done. 
# This is an extreme case but you get the idea.
# }
# NOT RUN {
# "##NOT RUN:" mean that this example hasn't been run on CRAN since its long. But you can run it!
# }

Run the code above in your browser using DataLab