Description Usage Arguments Details Value See Also Examples
Find rows with specified keys.
1 2 3 |
x |
the values to be matched. |
table |
the values to be matched against. |
default |
the value to return when no row
in the |
The lookup
and rowid
functions to the same thing, but have their
arguments transposed. Each finds the corresponding entry in the table
for each entry in x
; for values in x
with no match, return the
default
value.
The rowid
function is generic. The default implementation
converts table
with as.keyset
and converts x
with as.dataset
, then finds the rows in the table corresponding
to the rows in x
.
The lookup
function calls the rowid
generic.
A vector of row indices in table
for the corresponding rows in the
x
argument. Rows with no match get the default
value (converted
to numeric).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # look up single-component keys
table <- keyset(name = rownames(mtcars))
lookup(c("Valiant", "Fiat 128", "Delorean"), table)
# rowid returns the same result but has its arguments swapped
rowid(table, c("Valiant", "Fiat 128", "Delorean"))
# multi-component keys
keys <- keyset(k1 = rep(LETTERS[1:4], each = 8), k2 = rep(1:8, 4))
# look up a single item
lookup(record(k1 = "A", k2 = 5), keys)
# look up multiple items
lookup(dataset(k1 = c("A", "A", "B", "Z"),
k2 = c( 5, 100, 1, 3)), keys)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.