simpleaggregate: Title Combine rows sharing unique identifier to save all...

View source: R/rows_manage.R

simpleaggregateR Documentation

Title Combine rows sharing unique identifier to save all unique data to 1 row per identifier

Description

Title Combine rows sharing unique identifier to save all unique data to 1 row per identifier

Usage

simpleaggregate(
  dt,
  idcol,
  reformat = TRUE,
  disregard = c(NA, ""),
  prefkeep = FALSE,
  col = NULL
)

Arguments

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

Value

Returns data.frame aggregated to one row per idcol.

Examples

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")


DHatziioanou/simpleepi documentation built on Sept. 24, 2024, 5:25 a.m.