pMerge: Merge a Data Frame 'into' Another

Description Usage Arguments Examples

View source: R/pMerge.R

Description

This function will merge a data frame df2 'into' a data frame df1, preserving df1 as much as possible in the merger. Hence I call this a 'preserving' merge, or pMerge.

Usage

1
pMerge(df1, df2, by = intersect(names(df1), names(df2)), doCheck = FALSE)

Arguments

df1

the data.frame which we are preserving

df2

the data.frame we are merging into df1

by

character; name of the variable we are merging over

doCheck

boolean; set this if you want to perform more extensive (but slower) error checking

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
df1 <- data.frame( stringsAsFactors=FALSE,
  x=1:1000,
  y=sample(LETTERS, size=1000, replace=TRUE)
)

df2 <- data.frame( stringsAsFactors=FALSE,
  x=sample( 1:2000, size=2000, replace=TRUE ),
  z=sample( letters, size=2000, replace=TRUE ),
  q=sample( LETTERS, size=2000, replace=TRUE )
)

dMerged <- pMerge( df1, df2, by="x" )
stopifnot( all.equal( df1, dMerged[1:ncol(df1)] ) )

Kmisc documentation built on May 29, 2017, 1:43 p.m.

Related to pMerge in Kmisc...