mreverse: Match reversed values

View source: R/mreverse.R

mreverseR Documentation

Match reversed values

Description

Eliminates directionality of value pairs. Largely a wrapper around grp_reverse_pairs accepting single, double or multi-column data frame inputs. grp_reverse_pairs generates a list of unique reverse-value pairs, and mreverse assigns these identifiers to all entries of the given data frame. This is useful to convert directed network edges into undirected ones.

Usage

mreverse(x, cols, into, sep, as_fct = F)

Arguments

x

Either single- or multi column data frame. In case of data frame containing more than two columns, cols needs to identify either a single column (containing splitable strings) or two columns that hold the value pair.

cols

Vector of column names (or index) if x has more than two columns.

into

String. Name of additional column to store shared identifier.

sep

Single character for spliting single column string values

Details

A given list of directed dyads (e.g. "A-B", "B-A", "A-C", "C-A") is converted into undirected dyads such that "A-B" and "B-A" are both represented as "A-B".

Accepts both, a single character column to be split (e.g. "Student-Teacher") or two columns such as "Head", "Tail".

In case a single column is provided, needs to contain a string that can be split by a given separater sep.

Value

Original dataframe with additional column (specified by into) containing shared identifier between value pairs.

See Also

grp_reverse_pairs

Examples

#single column
x <- data.frame(a=c("A-B", "B-A", "A-B", "C-D", "D-C", "Z-P", "Z-P"), stringsAsFactors = F)
mreverse(x)

#two columns
x <- data.frame(a=c(1,2,3,4,5), b=c(2,1,4,3,5), d=c("A-B", "B-A", "C-D", "D-C", "F-F"), stringsAsFactors = F)
mreverse(x, cols=c(1,2))

#or again just the single column with string value pair
mreverse(x, cols=c("d"))


jmueller17/sociometrics documentation built on March 20, 2024, 1:04 a.m.