mergeDups: Merge duplicated lines into one entry

View source: R/mergeDups.R

mergeDupsR Documentation

Merge duplicated lines into one entry

Description

Merge duplicated lines into one entry according to one or some identifier(s). Note: this function may be quite slow when input data is large.

Usage

mergeDups(x, id = 1, sep = NULL)

Arguments

x

a data frame or tibble

id

column index of identical variable, which is used to detect duplication, default the first column.

sep

separator. If column(s) to merge only contain(s) numeric values, they can be merged with the default sep = NULL simply by adding them together. If character or string occurred, sep should be set to a string.

Author(s)

Yujie Liu

Examples

x <-
  data.frame(
    x1 = c("A", "A", "B", "A", "C", "B"),
    x2 = c(1, 1, 2, 1, 3, 2),
    x3 = c(100, 100, 200, 100, 300, 200),
    x4 = c(100, 200, 300, 400, 500, 600)
  )

mergeDups(x, id = 1)
mergeDups(x, id = 2, sep = "+")
mergeDups(x, id = 1:3, sep = ";")

liuyujie0136/tinyfuncr documentation built on Dec. 13, 2024, 8:49 a.m.