Learn R Programming

corkscrew (version 1.1)

apply.ctoc: Applying Categorical to Continuous conversion to a new dataframe

Description

Extrapolating the categorical to continuous conversion that is calculated from one dataframe to another dataframe.

Usage

apply.ctoc(y, x, data, newdata, min.obs)

Arguments

y
Response variable (categorical or continuous).
x
Predictor variables in the dataframe which are categorical and need to be converted into continuous.
data
Name of the dataframe from which the values of the categories have to be calculated.
newdata
Name of the dataframe to which the values of the categories have to be applied.
min.obs
The minimum number of observations within a category in a categorical variable to get converted into a continuous feature. All the categories which have observations less than the min.obs will form a different category.

Value

Returns a dataframe with converted features without replacing the original ones.

Details

This function is only for categorical variables. The min.obs refers to the minimum number of observations in the "data".

See Also

ctoc, tbin, apply.tbin.

Examples

Run this code
data(ChickWeight)
set.seed(2)
sample_ex <- sample(nrow(ChickWeight), size = 289, replace = FALSE, prob = NULL)
train <- ChickWeight[sample_ex,]
test <- ChickWeight[-sample_ex,colnames(ChickWeight) != "weight"]
# Returns the test dataframe with an added column "Diet_cont" by extrapolating it from train
head(apply.ctoc(y = "weight", "Diet", data = train, newdata = test, min.obs = 60))

Run the code above in your browser using DataLab