mreverse | R Documentation |
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.
mreverse(x, cols, into, sep, as_fct = F)
x |
Either single- or multi column data frame. In case of data frame containing more than
two columns, |
cols |
Vector of column names (or index) if |
into |
String. Name of additional column to store shared identifier. |
sep |
Single character for spliting single column string values |
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
.
Original dataframe with additional column (specified by into
) containing
shared identifier between value pairs.
grp_reverse_pairs
#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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.