Skip to contents

This function removes rows from a data frame where two specified columns have reversed duplicate values. It identifies pairs of columns that contain the same values but in reverse order, and retains only one instance of each pair.

Usage

remove_reversed_dupe_cols(df, col1, col2)

Arguments

df

A data frame containing the data to be processed.

col1

The name of the first column to check for reversed duplicates.

col2

The name of the second column to check for reversed duplicates.

Value

A data frame with reversed duplicate rows removed.

Details

This is useful for cleaning up data where the order of elements in the two columns doesn't matter, such as in undirected networks or paired observations.

Examples

if (FALSE) { # \dontrun{
# Create a sample data frame
df <- data.frame(
  var_1 = c(1, 2, 3, 4, 2) %>% paste0("street_", .),
  var_2 = c(2, 1, 4, 3, 1) %>% paste0("street_", .)
)

# Remove reversed duplicates
cleaned_df <- remove_reversed_dupe_cols(df, "var_1", "var_2")

} # }