cbind2: Combine two 'db.obj' Objects by Columns

cbind2-methodsR Documentation

Combine two db.obj Objects by Columns

Description

cbind2 or cbind combine two or multiple db.obj objects to form a new db.obj. And as.list does the opposite and expand a db.obj object into a list of db.obj objects with each one of them representing one column of the original db.obj object. as.list is usually used together with Reduce and Map.

Usage

## S4 method for signature 'db.obj,db.obj'
cbind2(x, y)

## S4 method for signature 'db.obj'
as.list(x, array = FALSE, ...)

Arguments

x, y

The signature of the method. Both arguments are db.obj objects.

array

logical, default is FALSE. When it is TRUE, the array columns are also expanded and all the elements are put into the resulting list. Otherwise, an array column is treated as a single item in the result.

...

In cbind they can be anything that can form new columns together with x. In as.list, it is not implemented yet.

Value

cbind2 or cbind: A db.Rquery object, which contains all columns of x and y.

as.list: A list of db.Rquery objects, which are the columns of x

Author(s)

Author: Predictive Analytics Team at Pivotal Inc.

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

See Also

db.array combines columns of a table/view into an array.

array.len measures the length of the array in an array column.

Examples

## Not run: 


## 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 table from the example data.frame "abalone"
delete('abalone', conn.id = cid)
x <- as.db.data.frame(abalone, 'abalone', conn.id = cid, verbose = FALSE)

## create a db.Rquery object that has two columns
z <- cbind(x$rings, x$length)

## plot prediction v.s. real value
plot(lookat(z, 100))

## expand the db.obj
unlist(Map(function(x)
               if (col.types(x) == "text")
                   paste(lk(unique(x)), collapse="-", sep="")
               else
                   lk(mean(x))),
           as.list(x))

## sum of all columns (excluding the 2nd column)
Reduce(function(left, right) left + right, as.list(x[-2]))

db.disconnect(cid, verbose = FALSE)

## End(Not run)

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