ctoc: Categorical variables into Continuous features

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/ctoc.R

Description

Converting categorical variables into continuous features using the mean of the response variable for the respective categories without using the index record.

Usage

1
ctoc(y, x, data, 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.

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.

Details

This function is only for categorical variables.

Value

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

Author(s)

Santhosh Sasanapuri

See Also

apply.ctoc, tbin, apply.tbin.

Examples

1
2
3
4
5
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))

Example output

Loading required package: ggplot2
Loading required package: gplots

Attaching package: 'gplots'

The following object is masked from 'package:stats':

    lowess

Loading required package: RColorBrewer
Loading required package: igraph

Attaching package: 'igraph'

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union

  Diet Chick weight Time Chick_cont Diet_cont
1    1     1     39    0   78.29730  102.9361
2    1     1     35    2   78.40541  102.9543
3    1    10     43    0   90.72727  102.9178
4    1    10     48    2   90.27273  102.8950
5    1    10     55    4   89.63636  102.8630
6    1    10     62    6   89.00000  102.8311

corkscrew documentation built on May 1, 2019, 8:23 p.m.