as.factor-methods: Convert one column of a 'db.obj' object into a categorical...

as.factor-methodsR Documentation

Convert one column of a db.obj object into a categorical variable

Description

Convert one column of a db.obj object into a categorical variable. The reference level for regressions can be selected using relevel.

Usage

## S4 method for signature 'db.obj'
as.factor(x)

## S4 method for signature 'db.obj'
relevel(x, ref, ...)

Arguments

x

A db.obj object. It must have only one column.

ref

A single value, which is the reference level that is used in the regressions.

...

Other arguments passed into the result. Not implemented yet.

Value

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(s)

Author: Predictive Analytics Team at Pivotal Inc.

Maintainer: Frank McQuillan, Pivotal Inc. fmcquillan@pivotal.io

See Also

When as.db.data.frame creates a table/view, it can create dummy variables for a categorical variable.

Examples

## 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)

greenplum-db/GreenplumR documentation built on Sept. 2, 2023, 8:09 a.m.