compareVars: Compare Table Variables

View source: R/compareVars.R

compareVarsR Documentation

Compare Table Variables

Description

Compares column names in two tables based on a given pattern. Provides information about which columns are present in which tables.

Usage

compareVars(x, y, pattern = "")

Arguments

x

A data frame representing the first table.

y

A data frame representing the second table.

pattern

A string pattern used to filter and compare only a subset of variables (column names).

Value

A list containing:

  • all: All column names from both tables.

  • common: Column names found in both tables.

  • onlyX: Column names found only in the first table (x).

  • onlyY: Column names found only in the second table (y).

  • exclusive: Column names found in only one of the two tables.

Examples

# Example tables
table1 <- data.frame(exclusive_1 = 1:5, common_1 = 6:10, common_2 = 11:15)
table2 <- data.frame(common_1 = 16:20, common_2 = 21:25, exclusive_2 = 26:30)

# Compare all columns (no pattern given)
compare_all <- compareVars(table1, table2)
compare_all$common
compare_all$exclusive
compare_all$onlyX
compare_all$onlyY

# compare only columns following a specific pattern
compare_wPattern <- compareVars(table1, table2, pattern = "1")
compare_wPattern$all
compare_wPattern$common

R.AlphA.Home documentation built on April 3, 2025, 5:53 p.m.