Learn R Programming

ETLUtils (version 1.5)

factorise: Put character vectors, columns of a data.frame or list elements as factor

Description

Put character vectors, columns of a data.frame or list elements as factor if they are character strings or optionally if they are logicals

Usage

factorise(x, logicals = FALSE, ...)

# S3 method for default factorise(x, logicals = FALSE, ...)

# S3 method for character factorise(x, logicals = FALSE, ...)

# S3 method for data.frame factorise(x, logicals = FALSE, ...)

# S3 method for list factorise(x, logicals = FALSE, ...)

Arguments

x

a character vector, a data.frame or a list

logicals

logical indicating if logical vectors should also be converted to factors. Defaults to FALSE.

...

optional arguments passed on to the methods

Value

The updated x vector/data.frame or list where the character vectors or optionally logical elements are converted to factors

See Also

as.factor, factor

Examples

Run this code
# NOT RUN {
x <- data.frame(x = 1:4, y = LETTERS[1:4], b = c(TRUE, FALSE, NA, TRUE), stringsAsFactors=FALSE)
str(factorise(x))
str(factorise(x, logicals = TRUE))
str(factorise(list(a = LETTERS, b = 1:10, c = pi, d = list(x = x))))
# }

Run the code above in your browser using DataLab