multi2weight.Rd
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.
multi2weight(edge.list, select_cols = NULL, aggr_expression = NULL)
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
' |
a tibble with 3 columns: source, target, and attr, where attr has been computed according to `aggr_expression`.
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)#> # A tibble: 6 x 3 #> # Groups: source [4] #> source target attr #> <chr> <chr> <int> #> 1 a b 1 #> 2 b c 1 #> 3 b d 1 #> 4 c a 1 #> 5 d a 3 #> 6 d b 1# edgelist with sum of attr multi2weight(el, aggr_expression='sum(attr)')#> # A tibble: 6 x 3 #> # Groups: source [4] #> source target attr #> <chr> <chr> <dbl> #> 1 a b 1 #> 2 b c 1 #> 3 b d 1 #> 4 c a 1 #> 5 d a 6 #> 6 d b 1# edgelist with mean of attr multi2weight(el, aggr_expression='mean(attr)')#> # A tibble: 6 x 3 #> # Groups: source [4] #> source target attr #> <chr> <chr> <dbl> #> 1 a b 1 #> 2 b c 1 #> 3 b d 1 #> 4 c a 1 #> 5 d a 2 #> 6 d b 1# edgelist with min of attr multi2weight(el, aggr_expression='min(attr)')#> # A tibble: 6 x 3 #> # Groups: source [4] #> source target attr #> <chr> <chr> <dbl> #> 1 a b 1 #> 2 b c 1 #> 3 b d 1 #> 4 c a 1 #> 5 d a 1 #> 6 d b 1# edgelist with max of attr multi2weight(el, aggr_expression='max(attr)')#> # A tibble: 6 x 3 #> # Groups: source [4] #> source target attr #> <chr> <chr> <dbl> #> 1 a b 1 #> 2 b c 1 #> 3 b d 1 #> 4 c a 1 #> 5 d a 3 #> 6 d b 1# edgelist with any() of attr2 multi2weight(el, aggr_expression='any(attr2)')#> # A tibble: 6 x 3 #> # Groups: source [4] #> source target attr #> <chr> <chr> <lgl> #> 1 a b TRUE #> 2 b c FALSE #> 3 b d TRUE #> 4 c a TRUE #> 5 d a TRUE #> 6 d b FALSE# edgelist with all() of attr2 multi2weight(el, aggr_expression='all(attr2)')#> # A tibble: 6 x 3 #> # Groups: source [4] #> source target attr #> <chr> <chr> <lgl> #> 1 a b TRUE #> 2 b c FALSE #> 3 b d TRUE #> 4 c a TRUE #> 5 d a FALSE #> 6 d b FALSE