compare: Comparing two databases assumed to be identical

Description Usage Arguments Value Author(s) Examples

View source: R/compare.r

Description

Compares two data frames assumed to be identical, prints the differences in the console and also returns the results in a data frame

Usage

1
compare(d1, d2, id, file.export = NULL)

Arguments

d1

first data frame

d2

second data frame

id

character string, primary key of the two data bases

file.export

character string, name of the XLS file exported

Value

A data frame containing the differences between the two data bases

Author(s)

Hugo Varet

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
N=100
data1=data.frame(id=1:N,a=rnorm(N),
                        b=factor(sample(LETTERS[1:5],N,TRUE)),
                        c=as.character(sample(LETTERS[1:5],N,TRUE)),
                        d=as.Date(32768:(32768+N-1),origin="1900-01-01"))
data1$c=as.character(data1$c)
data2=data1
data2$id[3]=4654
data2$a[30]=NA
data2$a[31]=45
data2$b=as.character(data2$b)
data2$d=as.character(data2$d)
data2$e=rnorm(N)
compare(data1,data2,"id")

Example output

Loading required package: survival
Comparing the two databases data1 and data2:

Individual(s) 3 in data1 but not in data2
Individual(s) 4654 in data2 but not in data1
Variable(s) e in data2 but not in data1

Variable a:
 id            data1_a data2_a
 30  0.183104516669571      NA
 31 -0.897807976240739      45

Variable b:
 b is factor in data1 while character in data2

Variable d:
 d is Date in data1 while character in data2

There are differences between the two databases

packHV documentation built on May 29, 2017, 11:01 a.m.