simpleaggregate | R Documentation |
Title Combine rows sharing unique identifier to save all unique data to 1 row per identifier
simpleaggregate(
dt,
idcol,
reformat = TRUE,
disregard = c(NA, ""),
prefkeep = FALSE,
col = NULL
)
dt |
data |
idcol |
column with unique identifiers to aggregate by |
reformat |
Optional; TRUE (default) reformats to original column classes. FALSE returns all as character. Use FALSE to avoid losing different dates per ID. |
disregard |
Optional; cell values to remove prior to aggregation eg NA, NULL, 0, -1. Default; NA, "". |
prefkeep |
Optional; Keep 1st record value where duplicate record values differ. Default; FALSE. |
col |
Optional; Columns to process with prefkeep. "all" will process all columns |
Returns data.frame aggregated to one row per idcol.
messy <- data.frame(ID = c(1,1,2,3),
data <- c("red", "yellow", "red", "green"))
clean <- simpleaggregate(
dt = messy,
idcol = "ID",
disregard=c(NULL,NA,""))
clean <- simpleaggregate(dt = messy,
idcol = "ID",
disregard=c(NULL,NA,""),
prefkeep = 1,
col = "all")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.