df_compare: Identify differences in two data frames

Description Usage Arguments Value Examples

View source: R/df_compare.R

Description

This function compares two data frames (including NA values) and returns the differing rows and columns which both data frames have in common

Usage

1
df_compare(df_1, df_2, by_vars)

Arguments

df_1

first data frame to compare

df_2

second data frame to compare

by_vars

a single or combination of variables for which the input data frames are unique

Value

a list whose individual members are data frames, one for each column containing a difference

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
df_1 <-
  data.frame(
    pt_id = sort(rep(1:10, 3)),
    vst_num= rep(1:3, 10),
    vals_1 = rbinom(30,10,0.5),
    vals_2 = runif(30),
    vals_3 = rnorm(30)
  )

df_2 <- df_1[ -8, ]

df_2[ c(3, 12), c('vals_1', 'vals_2', 'vals_3')] <- sample(c(NA, 99), 6, replace = T)

df_compare(
  df_1 = df_1,
  df_2 =  df_2,
  by_vars = c('pt_id', 'vst_num')
)

hild0146/hildenp documentation built on May 17, 2019, 3:58 p.m.