dataset: Dataset Objects

Description Usage Arguments Details Value Dataset Behavior See Also Examples

View source: R/dataset.R

Description

Create or test for dataset objects.

Usage

1
2
3
4
5

Arguments

...

dataset variables.

x

object to be converted or tested.

Details

These functions create or test for dataset objects, sets of variables measured on the same individuals. These individuals can optionally be identified by a set of keys, one for each individual. A dataset is like a data.frame in many respects, but exhibits some important differs (discussed below).

dataset creates a new dataset object with variables taken from the arguments to the method. Unnamed arguments get variable names taken from the quoted arguments.

as.dataset converts its argument to a dataset object. This is a generic function. The default implementation works as follows:

  1. A list or record argument gets converted to dataset of the same length with the argument's fields as variables.

  2. A vector-like argument gets converted to single-variable dataset.

  3. A matrix-like argument gets converted to a dataset with columns of the argument as variables.

The default conversion fails for rank-3 and higher arrays.

Value

dataset and as.dataset return dataset objects.

is.dataset returns TRUE or FALSE depending on whether its argument is a dataset.

Dataset Behavior

Datasets are similar to data.frame objects but exhibit some important differences:

  1. Datasets are record objects and inherit their subscripting behavior for getting or setting columns.

  2. Datasets can optionally assign keys to each row identifying the measured individuals. These keys can be of almost-arbitrary type and can have multiple components; see keys.

  3. Key values can be used as row subscripts to extract specified rows. A row subscript that itself has keys propagates its own keys to the result.

  4. Datasets can contain both vector-like and matrix-like variables. In particular, datasets can be nested within other datasets.

  5. Subscripting operations default to drop = FALSE.

  6. Variable names are not constrained to be unique. A dataset can have NULL names.

  7. Printing behavior is different; see print.dataset.

See Also

cbind.dataset, rbind.dataset, print.dataset, record.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
x <- dataset(letters, x = runif(26), y = rpois(26, 1))

# get and rename a column
x[c(foo = "x")]

# set multi-component keys
keys(x) <- dataset(k1 = LETTERS, k2 = 1:26)

# index with keys
x[record(k1 = "E", k2 = 5), ]
k <- keys(x)[c(5, 17, 2, 1), ]
x[k, ]

# propagate subscript keys to result
keys(k) <- dataset(foobar = c(4, 2, 0, -2))
x[k, ]

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