Learn R Programming

jwutil (version 1.2.3)

merge_better: Merge better

Description

Apply built-in R merge but with additional features for safety and information.

Usage

merge_better(x, y, by.x, by.y, all.x = FALSE, all.y = FALSE,
  affix = NULL, renameConflict = c("suffix", "prefix"),
  renameAll = c("no", "suffix", "prefix"), convert_factors = TRUE,
  verbose = FALSE)

mergeBetter(x, y, by.x, by.y, all.x = FALSE, all.y = FALSE, affix = NULL, renameConflict = c("suffix", "prefix"), renameAll = c("no", "suffix", "prefix"), convert_factors = TRUE, verbose = FALSE)

Arguments

x

data frame

y

data frame

by.x

field in x to merge on. Unlike merge, this is compulsory.

by.y

field in y to merge on. Unlike merge, this is compulsory.

all.x

outer join to keep all x values

all.y

outer join to keep all y values

affix

either prefix or suffix to disambiguate files. By default, this is the name of the table specified in y. In all other respects in this function, x and y are symmetric.

renameConflict

- determines whether prefix or suffix is added to disambiguate conflicting column names. Value can be "suffix", "prefix". Suffix is the default.

renameAll

- regardless of column name clashes, "prefix" or "suffix" with every field with original table name, or "no" for neither

convert_factors

Default is TRUE which causes factors to be converted to character before merge. This is almost certainly safer.

verbose

logical or numbers 0, 1 or 2. 1 or TRUE will give moderate verbosity, 2 will give full verbosity. 0 or FALSE turns off all messages.

Value

merged data frame

Examples

Run this code
# NOT RUN {
df <- data.frame(a = c("1", "2"), b = 1:2, stringsAsFactors = FALSE)
eg <- data.frame(a = c("1", "3"), b = 3:4, stringsAsFactors = FALSE)
mergeBetter(x = df, y = eg, by.x = "a", by.y = "a", verbose = TRUE)
# }

Run the code above in your browser using DataLab