The pmdplyr library accepts the use of multiple ID variables. However, you may wish to combine these into a single variable, or renumber the single variable you already have for some reason.

id_variable(..., .method = "number", .minwidth = FALSE)

Arguments

...

variables (vectors) that, together, make up the ID variables in the data and uniquely identifies the individual. Note that id_variable() will not check whether you've selected an appropriate set of variables; try running as_pibble() after getting your ID and time variables.

.method

Can be 'number', 'random', or 'character', as described below.

.minwidth

If .method = 'character', omits the additional spacing that makes the ID variable fixed-width and ensures uniqueness. WARNING: This option saves space but may in rare cases cause two individuals to have the same ID. Defaults to FALSE.

Details

By default, id_variable() will create a unique numeric identifier out of your ID variables, sequential following the order in the original data (.method='number'). However, you may want to remove the ordering and assign IDs randomly (.method='random'), or preserve all the original information and create a single fixed-width character ID variable that contains all the original information (.method='character').

Examples

data(SPrail) # I want to identify observations at the route (origin-destination)/year level # Let's make it a character variable so we can tell at a glance what route we're talking SPrail <- SPrail %>% dplyr::mutate(route_id = id_variable(origin, destination, .method = "character"))