Description Usage Arguments Value Author(s) Examples
View source: R/get_vertex_attr_aggregate.R
Calculate the group by aggregate of a specific vertex attribute
1 | get_vertex_attr_aggregate(g, attr, groups, func, ...)
|
g |
An 'igraph' object |
attr |
Character value, indicating the vertex attribute to be aggregated |
groups |
Vector of character or factor, which indicate the groups to be aggregated |
func |
Aggregation function |
... |
Optional arguments to be passed onto the aggregation function |
A vector or matrix object
Timothy Wong, timothy.wong@hotmail.co.uk
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # Use the postcode sector to derive the area
# Example: BS = Bristol; BA = Bath
library(igraph)
library(stringr)
area <- factor(str_extract(vertex_attr(BristolBathGraph, "name"),"^[A-Z]*"),
labels = c(BS="Bristol", BA="Bath"))
# Calculate the aggregate of vertex attribute
# Returns a vector object of length 2
# The names represent postcode area
# The value represent total population of each postcode area
get_vertex_attr_aggregate(g = BristolBathGraph,
groups = area,
attr = "population",
func = sum)
# Optional arguments can be passed onto `func` using `...`.
# This will calculate the percentiles of the population of each postcode area
# Returns a matrix object of 2 columns * 4 rows.
# The columns represent postcode areas
# The rows are names as '20%', '40%', '60%' and '80%'
# You may use `names=FALSE` to suppress row names (see documentation for `?quantile()`)
get_vertex_attr_aggregate(g = BristolBathGraph,
groups = area,
attr = "population",
func = quantile,
probs = c(0.2, 0.4, 0.6, 0.8))
get_vertex_attr_aggregate(g = BristolBathGraph,
groups = area,
attr = "population",
func = quantile,
probs = c(0.2, 0.4, 0.6, 0.8),
names = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.