1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/set_node_attr_w_fcn.R
3\name{set_node_attr_w_fcn}
4\alias{set_node_attr_w_fcn}
5\title{Set node attribute values with a graph function}
6\usage{
7set_node_attr_w_fcn(graph, node_attr_fcn, ..., column_name = NULL)
8}
9\arguments{
10\item{graph}{A graph object of class \code{dgr_graph}.}
11
12\item{node_attr_fcn}{The name of the function to use for creating a column of
13node attribute values. Valid functions are: \code{\link[=get_alpha_centrality]{get_alpha_centrality()}},
14\code{\link[=get_authority_centrality]{get_authority_centrality()}}, \code{\link[=get_betweenness]{get_betweenness()}}, \code{\link[=get_bridging]{get_bridging()}},
15\code{\link[=get_closeness]{get_closeness()}}, \code{\link[=get_cmty_edge_btwns]{get_cmty_edge_btwns()}}, \code{\link[=get_cmty_fast_greedy]{get_cmty_fast_greedy()}},
16\code{\link[=get_cmty_l_eigenvec]{get_cmty_l_eigenvec()}}, \code{\link[=get_cmty_louvain]{get_cmty_louvain()}}, \code{\link[=get_cmty_walktrap]{get_cmty_walktrap()}},
17\code{\link[=get_constraint]{get_constraint()}}, \code{\link[=get_degree_distribution]{get_degree_distribution()}}, \code{\link[=get_degree_histogram]{get_degree_histogram()}},
18\code{\link[=get_degree_in]{get_degree_in()}}, \code{\link[=get_degree_out]{get_degree_out()}}, \code{\link[=get_degree_total]{get_degree_total()}},
19\code{\link[=get_eccentricity]{get_eccentricity()}}, \code{\link[=get_eigen_centrality]{get_eigen_centrality()}}, \code{\link[=get_pagerank]{get_pagerank()}},
20\code{\link[=get_s_connected_cmpts]{get_s_connected_cmpts()}}, and \code{\link[=get_w_connected_cmpts]{get_w_connected_cmpts()}}.}
21
22\item{...}{Arguments and values to pass to the named function in
23\code{node_attr_fcn}, if necessary.}
24
25\item{column_name}{An option to supply a column name for the new node
26attribute column. If \code{NULL} then the column name supplied by the function
27will used along with a \verb{__A} suffix.}
28}
29\value{
30A graph object of class \code{dgr_graph}.
31}
32\description{
33From a graph object of class \code{dgr_graph} or a node data frame, set node
34attribute properties for all nodes in the graph using one of several
35whole-graph functions.
36}
37\examples{
38# Create a random graph using the
39# `add_gnm_graph()` function
40graph <-
41  create_graph() \%>\%
42  add_gnm_graph(
43    n = 10,
44    m = 22,
45    set_seed = 23) \%>\%
46  set_node_attrs(
47    node_attr = value,
48    values = rnorm(
49      n = count_nodes(.),
50      mean = 5,
51      sd = 1) \%>\% round(1))
52
53# Get the betweenness values for
54# each of the graph's nodes as a
55# node attribute
56graph_1 <-
57  graph \%>\%
58  set_node_attr_w_fcn(
59    node_attr_fcn = "get_betweenness")
60
61# Inspect the graph's internal
62# node data frame
63graph_1 \%>\% get_node_df()
64
65# If a specified function takes argument
66# values, these can be supplied as well
67graph_2 <-
68  graph \%>\%
69  set_node_attr_w_fcn(
70    node_attr_fcn = "get_alpha_centrality",
71    alpha = 2,
72    exo = 2)
73
74# Inspect the graph's internal
75# node data frame
76graph_2 \%>\% get_node_df()
77
78# The new column name can be provided
79graph_3 <-
80  graph \%>\%
81  set_node_attr_w_fcn(
82    node_attr_fcn = "get_pagerank",
83    column_name = "pagerank")
84
85# Inspect the graph's internal
86# node data frame
87graph_3 \%>\% get_node_df()
88
89# If `graph_3` is modified by
90# adding a new node then the column
91# `pagerank` will have stale data; we
92# can run the function again and re-use
93# the existing column name to provide
94# updated values
95graph_3 <-
96  graph_3 \%>\%
97  add_node(
98    from = 1,
99    to = 3) \%>\%
100  set_node_attr_w_fcn(
101    node_attr_fcn = "get_pagerank",
102    column_name = "pagerank")
103
104# Inspect the graph's internal
105# node data frame
106graph_3 \%>\% get_node_df()
107}
108\seealso{
109Other Node creation and removal:
110\code{\link{add_n_node_clones}()},
111\code{\link{add_n_nodes_ws}()},
112\code{\link{add_n_nodes}()},
113\code{\link{add_node_clones_ws}()},
114\code{\link{add_node_df}()},
115\code{\link{add_nodes_from_df_cols}()},
116\code{\link{add_nodes_from_table}()},
117\code{\link{add_node}()},
118\code{\link{colorize_node_attrs}()},
119\code{\link{copy_node_attrs}()},
120\code{\link{create_node_df}()},
121\code{\link{delete_nodes_ws}()},
122\code{\link{delete_node}()},
123\code{\link{drop_node_attrs}()},
124\code{\link{join_node_attrs}()},
125\code{\link{layout_nodes_w_string}()},
126\code{\link{mutate_node_attrs_ws}()},
127\code{\link{mutate_node_attrs}()},
128\code{\link{node_data}()},
129\code{\link{recode_node_attrs}()},
130\code{\link{rename_node_attrs}()},
131\code{\link{rescale_node_attrs}()},
132\code{\link{set_node_attr_to_display}()},
133\code{\link{set_node_attrs_ws}()},
134\code{\link{set_node_attrs}()},
135\code{\link{set_node_position}()}
136}
137\concept{Node creation and removal}
138