get_matched_columns_based_on_value: Detect pairs of columns with same unique values (order does...

Description Usage Arguments Value Examples

View source: R/utilities.R

Description

Detect pairs of columns with same unique values (order does not matter) in two dataframes.

Usage

1
2
3
4
5
6
get_matched_columns_based_on_value(
  df1,
  df2,
  only_allow_one_match = F,
  treat_fully_contain_as_identical = T
)

Arguments

df1

Dataframe1

df2

Dataframe2

only_allow_one_match

Default FALSE. This parameters is designed to get only one pair of matched columns between two dataframes to supply as parameters for merge function (when TRUE).

Value

A dataframe containing names of matched columns. Or a vetor containing names of matched columns when only_allow_one_match is TRUE and there do have one match.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
vec1 <- data.frame(col1=c('a','a','b','d'), a=c(1,2,3,4))
vec2 <- data.frame(col2=c('d','d','a','b'), b=c(1,2,4,5),a=c(1,2,3,4))
get_matched_columns_based_on_value(vec1, vec2)

#     match_1 match_2
# DF1    col1       a
# DF2    col2       a

vec2 <- data.frame(col2=c('d','d','a','b'))
get_matched_columns_based_on_value(vec1, vec2)

#     match_1
# DF1    col1
# DF2    col2

get_matched_columns_based_on_value(vec1, vec2, only_allow_one_match = T)

# "col1" "col2"

Tong-Chen/YSX documentation built on Jan. 25, 2021, 2:49 a.m.