Learn R Programming

keyed (version 0.1.3)

extend_id: Extend IDs to new rows

Description

Adds IDs to rows where the ID column is NA, preserving existing IDs. Useful after binding new data to an existing dataset with IDs.

Usage

extend_id(.data, .id = ".id")

Value

Data frame with IDs filled in for NA rows.

Arguments

.data

A data frame with an ID column (possibly with NAs).

.id

Column name for IDs (default: ".id").

Examples

Run this code
# Original data with IDs
old <- add_id(data.frame(x = 1:3))

# New data without IDs
new <- data.frame(.id = NA_character_, x = 4:5)

# Combine and extend
combined <- dplyr::bind_rows(old, new)
extend_id(combined)

Run the code above in your browser using DataLab