unfactorize | R Documentation |
Coerce all columns in the object from factor
.
unfactorize(object, ...)
## S4 method for signature 'factor'
unfactorize(object)
## S4 method for signature 'DFrame'
unfactorize(object, j = NULL)
## S4 method for signature 'data.frame'
unfactorize(object, j = NULL)
object |
Object. |
j |
|
... |
Additional arguments. |
Modified object, with factor
coerced back to atomic vector.
Updated 2023-09-20.
Warning section of help("factor")
.
R FAQ 7.10: How do I convert factors to numeric?
stringsAsFactors
for read.table
and data.frame
.
https://stackoverflow.com/questions/3418128/
forcats package.
## factor ====
object <- as.factor(c(100L, 100L, 101L, 101L))
## Coercion with `as.numeric` or `as.integer` don't work the way we want.
print(as.numeric(object))
print(as.integer(object))
object <- factorize(object)
print(object)
## DFrame ====
object <- S4Vectors::DataFrame(
"a" = as.factor(c(100L, 100L, 101L, 101L)),
"b" = as.factor(c("a", "b", "a", "b"))
)
print(object)
object <- unfactorize(object)
print(object)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.