ctoc {corkscrew} | R Documentation |
Converting categorical variables into continuous features using the mean of the response variable for the respective categories without using the index record.
ctoc(y, x, data, min.obs)
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. |
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. |
This function is only for categorical variables.
Returns a dataframe with converted features without replacing the original ones.
Santhosh Sasanapuri
data(ChickWeight)
# Converting the "Chick" variable into factor from ord.factor for demonstration purposes.
ChickWeight$Chick <- as.factor(as.numeric(ChickWeight$Chick))
# Returns a dataframe with two added columns for "Chick" and "Diet"
head(ctoc(y = "weight", x = c("Chick","Diet"), data = ChickWeight, min.obs = 12))