Learn R Programming

joinspy (version 0.7.3)

join_explain: Explain Row Count Changes After a Join

Description

After performing a join, use this function to understand why the row count changed. It analyzes the original tables and the result to explain the difference.

Usage

join_explain(result, x, y, by, type = NULL)

Value

Invisibly returns a list with explanation details. Prints a human-readable explanation.

Arguments

result

The result of a join operation.

x

The original left data frame.

y

The original right data frame.

by

A character vector of column names used in the join.

type

Character. The type of join that was performed. One of "left", "right", "inner", "full". If NULL (default), attempts to infer the join type from row counts.

See Also

join_spy(), join_diff()

Examples

Run this code
orders <- data.frame(id = c(1, 2, 2, 3), value = 1:4)
customers <- data.frame(id = c(1, 2, 2, 4), name = c("A", "B1", "B2", "D"))

result <- merge(orders, customers, by = "id", all.x = TRUE)

# Explain why we got more rows than expected
join_explain(result, orders, customers, by = "id", type = "left")

Run the code above in your browser using DataLab