Learn R Programming

SamplingStrata (version 1.5-4)

var.bin: Allows to transform a continuous variable into a categorical ordinal one by applying a modified version of the k-means clustering function in the 'stats' package.

Description

The optimization of a frame stratification is applicable only in presence of all categorical auxiliary variables in the frame. If one or more continuous auxiliary variables are in the frame, it is necessary to pre-process in order to convert them into categorical (ordinal) variables. The applied method is the "k-means" clustering method contained in the in "stats" package. This function ensures that the final result is in an ordered categorical variable.

Usage

var.bin(x,
		bins=3,
		iter.max=100)

Value

Binned variable

Arguments

x

Continuous variable to be transformed into a categorical one

bins

Number of values of the resulting categorical variable

iter.max

Maximum number of iterations of the clustering algorithm

Examples

Run this code
# \donttest{
library(SamplingStrata)
data(swissmunicipalities)
data(swissframe)
swissframe$X1 <- var.bin(swissmunicipalities$POPTOT,bins = 18)
table(swissframe$X1)
tapply(swissmunicipalities$POPTOT,swissframe$X1,mean)
# }

Run the code above in your browser using DataLab