x <- data.frame(tel_1 = c(111, 222, 444, 555),
tel_2 = c(222, 666, 666, 555),
name = paste0("name", 1:4))
# rows 1, 2, 3 share the same phone numbers
dedupe_wide(x,
cols_dedupe = c("tel_1", "tel_2"),
cols_expand = "name")
# first three collapsed into one, for name4 kept only one phone number (555)
# 'name1', 'name2', 'name3' kept in new columns
y <- data.frame(tel_1 = c(777, 888, NA, NA),
tel_2 = c(888, 777, NA, NA),
name = paste0("name", 5:8))
# rows 3 and 4 has only missing data
dedupe_wide(y,
cols_dedupe = c("tel_1", "tel_2"),
cols_expand = "name")
# first two rows collapsed into one, nothing change for the rest of rows
Run the code above in your browser using DataLab