Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

factorise

Change the class of variables to factor


Description

Takes in data and colNames, and returns the data with all variables mentioned in colNames converted to factor

Usage

factorise(data, colNames)

Arguments

data

a data.frame or data.table

colNames

a character vector of variable names to be converted to factor

Details

We often face the task of converting a bunch of variables to factor. This function is particularly useful in such a situation. Just specify the data and variable names and all of them will be converted to factor.

It works for both 'data.frame' and 'data.table', and the output is data of the same class as that of input.

Value

data of same class as input with specified variables converted to factor

Author(s)

Akash Jain

See Also

Examples

# A 'data.frame'
df <- data.frame(x = c(1, 2, 3, 4, 5),
                 y = c('a', 'b', 'c', 'd', 'e'),
                 z = c(1, 1, 0, 0, 1))

# Change the class of variables y and z to factors
dfFac <- factorise(data = df, colNames = c('y', 'z'))

StatMeasures

Easy Data Manipulation, Data Quality and Statistical Checks

v1.0
GPL-2
Authors
Akash Jain
Initial release
2015-03-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.