keyholder-id {keyholder} | R Documentation |
Add id column and key
Description
Functions for creating id column and key.
Usage
use_id(.tbl)
compute_id_name(x)
add_id(.tbl)
key_by_id(.tbl, .add = FALSE, .exclude = FALSE)
Arguments
.tbl |
Reference data frame. |
x |
Character vector of names. |
.add , .exclude |
Parameters for |
Details
use_id()
assigns as keys a tibble with column '.id'
and row numbers of .tbl
as values.
compute_id_name()
computes the name which is different from every
element in x
by the following algorithm: if '.id' is not present in x
it
is returned; if taken - '.id1' is checked; if taken - '.id11' is checked and
so on.
add_id()
creates a column with unique name (computed with
compute_id_name()
) and row numbers as values (grouping is ignored). After
that puts it as first column.
key_by_id()
is similar to add_id()
: it creates a column with unique name
and row numbers as values (grouping is ignored) and calls key_by()
function
to use this column as key. If .add
is FALSE
unique name is computed based
on .tbl
column names; if TRUE
then based on .tbl
and its keys column
names.
Examples
mtcars %>% use_id()
mtcars %>% add_id()
mtcars %>% key_by_id(.exclude = TRUE)