addID: add ID column

View source: R/makeQueryTable.R

addIDR Documentation

add ID column

Description

Adds an ID column to a data frame

Usage

addID(
  df,
  id_cols = c("Antigen", "Study"),
  new_col = "ID",
  warn = TRUE,
  sep = "__",
  overwrite = TRUE,
  verbose = TRUE
)

Arguments

df

A data.frame or tibble

id_cols

(character(n)) Names of columns to paste to form ID column

new_col

(character(1), default: "ID") Name of new ID column

warn

(TRUE/FALSE, default: TRUE) If TRUE, warn if IDs are not unique

sep

(Default: __) Delimiter to use for pasting columns to form ID

overwrite

Should new_col be regenerated if it already exists in df? (logical(1), default: TRUE)

verbose

Should program status messages be printed? Default: TRUE

Details

Pastes a group of columns together to form an ID column. If pasted values do not uniquely identify rows, adds a number to the end. If ID column already exists, this function will check if the ID uniquely identifies rows and will do nothing if this is the case. If the ID column exists and does not uniquely identify rows, it will be regenerated and overwritten.

Value

df with an extra ID column

df with an additional ID column, by default named "ID", which uniquely identifies each row. The ID column is created by pasting together the columns named in id_cols, and adding numbers if this is insufficient to uniquely identify rows.

Author(s)

Helen Lindsay

Examples

df <- data.frame(Study = c("A", "B", "B"),
                Antigen = c("CD4","CD8","CD8"))
addID(df)

HelenLindsay/AbNames documentation built on June 6, 2023, 1:18 p.m.