library(tidyverse)
library(glue)
#>
#> Attaching package: 'glue'
#> The following object is masked from 'package:dplyr':
#>
#> collapse
dupe_df <- function(.data){
map_dfr(.data, function(x) duplicated(x)*1)
}
bind_dup <- function(.data){
dupes <- dupe_df(.data)
names(dupes) <- glue("{names(.data)}_dup")
bind_cols(.data, dupes)
}
df <- tibble(x = c(1,1,3),
y = c(1,2,2),
z = c(2,2,4))
bind_dup(df)
#> # A tibble: 3 x 6
#> x y z x_dup y_dup z_dup
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 1 2 0 0 0
#> 2 1 2 2 1 0 1
#> 3 3 2 4 0 1 0
dupe_df(df)
#> # A tibble: 3 x 3
#> x y z
#> <dbl> <dbl> <dbl>
#> 1 0 0 0
#> 2 1 0 1
#> 3 0 1 0
# use dev visdat to get vis_binary
# install_github("ropensci/visdat")
library(visdat)
vis_binary(dupe_df(df))
Created on 2020-11-04 by the reprex package (v0.3.0)