Description Usage Arguments Details Value Note Examples
Convert character columns in a data.frame to factors.
1 | dfFactorize(df, only = c(), ignore = c())
|
df |
A data.frame. |
only |
A vector of column names. Only convert these columns to factors. |
ignore |
A vector of column names. Do not convert these columns. |
Given a data.frame, convert character columns to factors. By default, all character columns are converted, but the user can specify which columns to convert or to not convert.
A data.frame with all character columns (or only a subset of them if the parameters were set) converted to factors.
a data.frame with character columns converted to factors.
If any of the names in only
or ignore
are not valid
columns, an error is raised.
Only one of only
or ignore
can be used in a single call.
1 2 3 4 5 6 7 8 9 10 11 12 | df <- data.frame(a = 1:3, b = letters[1:3], c = LETTERS[1:3],
stringsAsFactors = FALSE)
str(df)
str(dfFactorize(df))
str(dfFactorize(df, only = "b"))
str(dfFactorize(df, ignore = "b"))
str(dfFactorize(df, ignore = c("b", "c")))
str(dfFactorize(df, only = c("a")))
# The following examples result in errors
## Not run: str(dfFactorize(df, only = c("z")))
## Not run: str(dfFactorize(df, only = "b", ignore = "c"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.