multi2weight: Generate weighted edge list from an edge list with...

Description Usage Arguments Value Examples

View source: R/edgelists.R

Description

The attribute reporting the aggregated weight of the multiedges is computed according to the expression specified in 'aggr_expression'. When no expression is specified, the 'attr' column returns the multiedge multiplicity.

Usage

1
multi2weight(edge.list, select_cols = NULL, aggr_expression = NULL)

Arguments

edge.list

dataframe containing a (weighted) edgelist.

select_cols

optional vector of 2 elements specifying which columns are the source,target for the edges from which building the weighted edge list. Otherwise column 1 is assumed to be the source and column 2 the target.

aggr_expression

string, the expression used to compute the aggregated value in the adjacency matrix in the presence of multiedges. It defaults to 'dplyr::n()'. If 'edge.list' contains other columns such as 'weight', examples of 'aggr_expression' could be '"mean(weight)"' to report the average of the 'weight' column of the multiedges, '"min(weight)"' to report the minimum of the 'weight' column of the multiedges.

Value

a tibble with 3 columns: source, target, and attr, where attr has been computed according to 'aggr_expression'.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
el <- data.frame(from= c('a','b','b','c','d','d','d','d'),
             to  = c('b','c','d','a','b','a','a','a'),
             attr= c( 1,  1,  1 , 1 , 1 , 1,  2 , 3 ),
            attr2= c( TRUE,  FALSE,  TRUE , TRUE , FALSE , TRUE,  TRUE , FALSE ))
# edgelist with multiedge multiplicities
multi2weight(el)

# edgelist with sum of attr
multi2weight(el, aggr_expression='sum(attr)')

# edgelist with mean of attr
multi2weight(el, aggr_expression='mean(attr)')

# edgelist with min of attr
multi2weight(el, aggr_expression='min(attr)')

# edgelist with max of attr
multi2weight(el, aggr_expression='max(attr)')

# edgelist with any() of attr2
multi2weight(el, aggr_expression='any(attr2)')

# edgelist with all() of attr2
multi2weight(el, aggr_expression='all(attr2)')

gi0na/adjConvertR documentation built on Jan. 7, 2022, 4:48 a.m.