Description Usage Arguments Examples
View source: R/data_manipulation.R
Adds a new unique ID to each member of a group in a dataframe. This is especially useful when processing data for upload to a database that uses integer IDs as unique primary keys. A single unique ID can be generated for each member of a group without first having to separate out the group and filtering to unique values.
1 | add_intid(dat, key_cols, id_name, start_id)
|
dat |
A dataframe |
key_cols |
The group of variables that will be assigned a unique ID |
id_name |
The name to assign to the ID variable |
start_id |
The ID value used to start the ID sequence. If |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Create an example dataframe
dat = tibble::tibble(lat = c(rep(47.6590, 7),
rep(47.6348, 3),
47.9033),
lon = c(rep(-122.4657, 4),
rep(-122.8743, 3),
rep(-122.8876, 2),
-122.8345, -122.4443),
species = c("chum", "chin", "chin",
"sthd", "chin", "sthd",
"sthd", "chum", "chum",
"pink", "pink"))
# Add an integer ID, grouped by the key columns
dat = add_intid(dat, key_cols = c("lat", "lon", "species"),
id_name = "survey_id", start_id = 100)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.