powered by
Maps values in a column of a data.frame (query) to new values using a named vector or list (map), optionally creating a new column or replacing the original.
map
map_column( query, by, map, to = "mapped", overwrite = FALSE, default = "unknown", preview = TRUE )
A data.frame with a new or modified column based on the mapping (returned invisibly).
A data.frame containing the column to be mapped.
A string. Column name in query to be mapped.
query
A named vector or list. Names are original values, values are mapped values.
A string. Name of the column to store mapped results (if overwrite = FALSE).
overwrite = FALSE
Logical. Whether to replace the by column with mapped values. Default: FALSE.
by
Default value to assign if no match is found. Default: "unknown".
Logical. Whether to print preview of result (default TRUE).
df <- data.frame(gene = c("TP53", "BRCA1", "EGFR", "XYZ")) gene_map <- c("TP53" = "Tumor suppressor", "EGFR" = "Oncogene") map_column(df, by = "gene", map = gene_map, to = "label")
Run the code above in your browser using DataLab