cbind: Combining Columns or Rows

Description Usage Arguments Details Value Binding Columns Binding Rows See Also Examples

Description

Create a new dataset by concatenating columns or rows together.

Usage

1
2
3
4
## S3 method for class 'dataset'
cbind(..., deparse.level = 1)
## S3 method for class 'dataset'
rbind(..., deparse.level = 1)

Arguments

...

objects to concatenate.

deparse.level

ignored.

Details

The cbind.dataset treats its arguments as columns or sets of columns, and binds them together into a single dataset. The rbind.dataset acts similarly, but treats its arguments as rows.

For both functions, NULL arguments get ignored. If there are no non-NULL arguments, then the result is NULL.

As with c.record, we explicitly export the method instances to allow control over method dispatch. A call to the generic cbind or rbind function will only dispatch to the dataset instance if all arguments are atomic or datasets. Call cbind.dataset or rbind.dataset explicitly if you want the dataset instance of one of these methods.

Value

A dataset with columns or rows taken from the non-NULL arguments, or NULL if there are no non-NULL arguments.

Binding Columns

For cbind.dataset, vector-like arguments get converted to single-column datasets, and matrix-like arguments get converted to datasets.

If argument names are provided, then these get used for the vector-like arguments, or they become prefixes (with .) of matrix-like arguments. Otherwise, unnamed vector-like arguments get their names taken from the quoted arguments.

All arguments must have the same number of rows. If any arguments have non-NULL keys, then these get propagated to the result. If two or more arguments have non-NULL keys, then they must be identical.

Binding Rows

For rbind.dataset, vector-like arguments get converted to single-row datasets, and matrix-like arguments get converted to datasets.

Argument names are not allowed.

All arguments must have the same number of columns. If any arguments have non-NULL names, then these get propagated to the result. If two or more arguments have non-NULL names, then they must be identical.

See Also

dataset, c.record.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# bind columns together
x <- 1:5
y <- letters[1:5]
z <- dataset(foo = rnorm(5), bar = logical(5))

cbind.dataset(x, y, z) # vector names taken from arguments
cbind.dataset(a = x, b = y, c = z) # alternative names

# bind rows together
rbind.dataset(x, y)

rbind.dataset(mtcars[1:3, ], 1:11, mtcars[20:25, ])

# propagate names to the result
names(y) <- LETTERS[1:5]
rbind.dataset(x, y)

# mismatched names result in an error
names(x) <- LETTERS[5:1]
## Not run: rbind.dataset(x, y)

patperry/r-frame documentation built on May 6, 2019, 8:34 p.m.