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

defactorize

Change Factors in Data.frames to Character Vectors


Description

Looks at each column in a data.frame, and converts factors to character vectors.

Usage

defactorize(df)

Arguments

df

a data.frame

Details

The function simply scans each column in a data.frame looking for factor columns. For each factor column it calls the ‘as.character()’ function to convert the column to a character vector.

Value

Returns a data.frame where every factor column has been converted to a character vector.

Note

This function simplifies editing data.frames by allowing users to edit character columns (which have no levels constraints) and then converting the results to factors for modeling. It is often used in a cycle of

defactorize(df)

edit the columns as necessary to correct errors or simplify

factorize(df)

Author(s)

See Also

Examples

data(brycesite)
brycesite <- defactorize(brycesite)
brycesite$quad[brycesite$quad=='bp'] <- 'BP'
brycesite <- factorize(brycesite)

labdsv

Ordination and Multivariate Analysis for Ecology

v2.0-1
GPL (>= 2)
Authors
David W. Roberts <droberts@montana.edu>
Initial release

We don't support your browser anymore

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