keys: Data Keys

Description Usage Arguments Details Value See Also Examples

View source: R/keys.R

Description

Get or set the keys associated with a set of values.

Usage

1
2
keys(x)
keys(x) <- value

Arguments

x

an object.

value

keys for x, or NULL.

Details

A dataset object and other similar objects can have a keys attribute identifying the data values in the object. This attribute is a dataset with unique rows, called a keyset.

Use keys(x) to retrieve the keys attribute for the rows in x. Use keys(x)<- value to set attribute, or keys(x) <- NULL to drop the keys.

Value

keys(x) is a keyset with the same number of rows as x.

See Also

dataset, keyset, lookup.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# data.frame objects do not have keys
keys(mtcars)

# you can set keys on datasets
x <- as.dataset(mtcars)
keys(x) <- keyset(name = rownames(mtcars))

# 'keys' can be scalar...
keys(x) <- runif(32)

# ...or 'keys' can have multiple columns
keys(x) <- keyset(k1 = rep(LETTERS[1:4], each = 8),
                  k2 = rep(1:8, 4))

# set 'keys' to NULL to remove
keys(x) <- NULL

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