Description Usage Arguments Details Value Dataset Behavior See Also Examples
Create or test for dataset objects.
1 2 3 4 5 | dataset(...)
as.dataset(x)
is.dataset(x)
|
... |
dataset variables. |
x |
object to be converted or tested. |
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:
A list or record argument gets converted to dataset of the same length with the argument's fields as variables.
A vector-like argument gets converted to single-variable dataset.
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.
dataset
and as.dataset
return dataset objects.
is.dataset
returns TRUE
or FALSE
depending on whether
its argument is a dataset.
Datasets are similar to data.frame
objects but exhibit some
important differences:
Datasets are record
objects and inherit their
subscripting behavior for getting or setting columns.
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
.
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.
Datasets can contain both vector-like and matrix-like variables. In particular, datasets can be nested within other datasets.
Subscripting operations default to drop = FALSE
.
Variable names are not constrained to be unique. A dataset
can have NULL
names.
Printing behavior is different; see print.dataset
.
cbind.dataset
, rbind.dataset
,
print.dataset
, record
.
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, ]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.