as.factor-methods | R Documentation |
db.obj
object into a categorical variable Convert one column of a db.obj
object into a categorical
variable. The reference level for regressions can be selected using relevel
.
## S4 method for signature 'db.obj'
as.factor(x)
## S4 method for signature 'db.obj'
relevel(x, ref, ...)
x |
A |
ref |
A single value, which is the reference level that is used in the regressions. |
... |
Other arguments passed into the result. Not implemented yet. |
A db.Rquery
object. It has only one column which is categorical. By default, a reference level is automatically selected in regressions, which is usually the minimum of all levels, but one can easily change the reference level using relevel
.
Author: Predictive Analytics Team at Pivotal Inc.
Maintainer: Frank McQuillan, Pivotal Inc. fmcquillan@pivotal.io
When as.db.data.frame
creates a table/view, it can create dummy variables for a
categorical variable.
## Not run:
## get help for a method
## help("as.factor,db.obj-method")
## set up the database connection
## Assume that .port is port number and .dbname is the database name
cid <- db.connect(port = .port, dbname = .dbname, verbose = FALSE)
## create a temporary table from the example data.frame "abalone"
x <- as.db.data.frame(abalone, conn.id = cid, verbose = FALSE)
## set sex to be a categorical variable
x$sex <- as.factor(x$sex)
## another temporary table
z <- as.db.data.frame(abalone, conn.id = cid, verbose = FALSE)
## using relevel to change the reference level
x$sex <- relevel(x$sex, ref = "M")
db.disconnect(cid, verbose = FALSE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.