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

Description Usage Arguments Value See Also Examples

View source: R/utils.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
factorise(x, logicals = FALSE, ...)

## Default S3 method:
factorise(x, logicals = FALSE, ...)

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

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

## S3 method for class '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

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

jwijffels/ETLUtils documentation built on Aug. 3, 2020, 11:59 a.m.