File: attribute.methods.Rd

package info (click to toggle)
r-cran-network 1.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,516 kB
  • sloc: ansic: 2,491; sh: 13; makefile: 2
file content (302 lines) | stat: -rw-r--r-- 9,550 bytes parent folder | download | duplicates (2)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/access.R
\name{attribute.methods}
\alias{attribute.methods}
\alias{delete.edge.attribute}
\alias{delete.edge.attribute.network}
\alias{delete.network.attribute}
\alias{delete.network.attribute.network}
\alias{delete.vertex.attribute}
\alias{delete.vertex.attribute.network}
\alias{get.edge.attribute}
\alias{get.edge.attribute.network}
\alias{get.edge.attribute.list}
\alias{get.edge.value}
\alias{get.edge.value.network}
\alias{get.edge.value.list}
\alias{get.network.attribute}
\alias{get.network.attribute.network}
\alias{get.vertex.attribute}
\alias{get.vertex.attribute.network}
\alias{list.edge.attributes}
\alias{list.edge.attributes.network}
\alias{list.network.attributes}
\alias{list.network.attributes.network}
\alias{list.vertex.attributes}
\alias{list.vertex.attributes.network}
\alias{network.vertex.names}
\alias{network.vertex.names<-}
\alias{set.edge.attribute}
\alias{set.edge.attribute.network}
\alias{set.edge.value}
\alias{set.edge.value.network}
\alias{set.network.attribute}
\alias{set.network.attribute.network}
\alias{set.vertex.attribute}
\alias{set.vertex.attribute.network}
\title{Attribute Interface Methods for the Network Class}
\usage{
delete.edge.attribute(x, attrname, ...)

\method{delete.edge.attribute}{network}(x, attrname, ...)

delete.network.attribute(x, attrname, ...)

\method{delete.network.attribute}{network}(x, attrname, ...)

delete.vertex.attribute(x, attrname, ...)

\method{delete.vertex.attribute}{network}(x, attrname, ...)

get.edge.attribute(x, ..., el)

\method{get.edge.attribute}{network}(
  x,
  attrname,
  unlist = TRUE,
  na.omit = FALSE,
  null.na = FALSE,
  deleted.edges.omit = FALSE,
  ...,
  el
)

\method{get.edge.attribute}{list}(
  x,
  attrname,
  unlist = TRUE,
  na.omit = FALSE,
  null.na = FALSE,
  deleted.edges.omit = FALSE,
  ...,
  el
)

get.edge.value(x, ...)

\method{get.edge.value}{network}(
  x,
  attrname,
  unlist = TRUE,
  na.omit = FALSE,
  null.na = FALSE,
  deleted.edges.omit = FALSE,
  ...
)

\method{get.edge.value}{list}(
  x,
  attrname,
  unlist = TRUE,
  na.omit = FALSE,
  null.na = FALSE,
  deleted.edges.omit = FALSE,
  ...
)

get.network.attribute(x, ...)

\method{get.network.attribute}{network}(x, attrname, unlist = FALSE, ...)

get.vertex.attribute(x, ...)

\method{get.vertex.attribute}{network}(
  x,
  attrname,
  na.omit = FALSE,
  null.na = TRUE,
  unlist = TRUE,
  ...
)

list.edge.attributes(x, ...)

\method{list.edge.attributes}{network}(x, ...)

list.network.attributes(x, ...)

\method{list.network.attributes}{network}(x, ...)

list.vertex.attributes(x, ...)

\method{list.vertex.attributes}{network}(x, ...)

network.vertex.names(x)

network.vertex.names(x) <- value

set.edge.attribute(x, attrname, value, e, ...)

\method{set.edge.attribute}{network}(x, attrname, value, e = seq_along(x$mel), ...)

set.edge.value(x, attrname, value, e, ...)

\method{set.edge.value}{network}(x, attrname, value, e = seq_along(x$mel), ...)

set.network.attribute(x, attrname, value, ...)

\method{set.network.attribute}{network}(x, attrname, value, ...)

set.vertex.attribute(x, attrname, value, v = seq_len(network.size(x)), ...)

\method{set.vertex.attribute}{network}(x, attrname, value, v = seq_len(network.size(x)), ...)
}
\arguments{
\item{x}{an object of class \code{network}, or a list of edges
(possibly \code{network$mel}) in \code{get.edge.attribute}.}

\item{attrname}{the name of the attribute to get or set.}

\item{...}{additional arguments}

\item{el}{Deprecated; use \code{x} instead.}

\item{unlist}{logical; should retrieved attribute values be
\code{\link{unlist}}ed prior to being returned?}

\item{na.omit}{logical; should retrieved attribute values corresponding to
vertices/edges marked as 'missing' be removed?}

\item{null.na}{logical; should \code{NULL} values (corresponding to vertices
or edges with no values set for the attribute) be replaced with \code{NA}s
in output?}

\item{deleted.edges.omit}{logical: should the elements corresponding to
deleted edges be removed?}

\item{value}{values of the attribute to be set; these should be in
\code{vector} or \code{list} form for the \code{edge} and \code{vertex}
cases, or \code{matrix} form for \code{set.edge.value}.}

\item{e}{IDs for the edges whose attributes are to be altered.}

\item{v}{IDs for the vertices whose attributes are to be altered.}
}
\value{
For the \code{list.attributes} methods, a vector containing
attribute names.  For the \code{get.attribute} methods, a list containing
the values of the attribute in question (or simply the value itself, for
\code{get.network.attribute}).  For the \code{set.attribute} and
\code{delete.attribute} methods, a pointer to the updated \code{network}
object.
}
\description{
These methods get, set, list, and delete attributes at the
network, edge, and vertex level.
}
\details{
The \code{list.attributes} functions return the names of all edge,
network, or vertex attributes (respectively) in the network.  All
attributes need not be defined for all elements; the union of all extant
attributes for the respective element type is returned.

The \code{get.attribute} functions look for an edge, network, or vertex
attribute (respectively) with the name \code{attrname}, returning its
values.  Note that, to retrieve an edge attribute from all edges within
a network \code{x}, \code{x$mel} should be used as the first argument to
\code{get.edge.attribute}; \code{get.edge.value} is a convenience function
which does this automatically. As of v1.7.2, if a \code{network} object is
passed to \code{get.edge.attribute} it will automatically call
\code{get.edge.value} instead of returning NULL. When the parameters
\code{na.omit},  or \code{deleted.edges.omit} are used, the position index
of the attribute values returned will not correspond to the vertex/edge
id.  To preserved backward compatibility, if the edge attribute
\code{attrname} does not exist for any edge, \code{get.edge.attribute}
will still return \code{NULL} even if \code{null.na=TRUE}

\code{network.vertex.names} is a convenience function to extract the
\code{"vertex.names"} attribute from all vertices.

The \code{set.attribute} functions allow one to set the values of edge,
network, or vertex attributes.  \code{set.edge.value} is a convenience
function which allows edge attributes to be given in adjacency matrix
form, and the assignment form of \code{network.vertex.names} is likewise
a convenient front-end to \code{set.vertex.attribute} for vertex names.
The \code{delete.attribute} functions, by contrast, remove the named
attribute from the network, from all edges, or from all vertices (as
appropriate).  If \code{attrname} is a vector of attribute names, each
will be removed in turn.  These functions modify their arguments in place,
although a pointer to the modified object is also (invisibly) returned.

Additional practical example of how to load and attach attributes are on the
\code{\link{loading.attributes}} page.

Some attribute assignment/extraction can be performed conveniently through
the various extraction/replacement operators, although they may be less
efficient.  See the associated man page for details.
}
\note{
As of version 1.9 the \code{set.vertex.attribute} function can accept
and modify multiple attributes in a single call to improve efficiency.
For this case \code{attrname} can be a list or vector of attribute names
and \code{value} is a list of values corresponding to the elements of
\code{attrname} (can also be a list of lists of values if elements in v
should have different values).
}
\examples{
#Create a network with three edges
m<-matrix(0,3,3)
m[1,2]<-1; m[2,3]<-1; m[3,1]<-1
g<-network(m)

#Create a matrix of values corresponding to edges
mm<-m
mm[1,2]<-7; mm[2,3]<-4; mm[3,1]<-2

#Assign some attributes
set.edge.attribute(g,"myeval",3:5)
set.edge.value(g,"myeval2",mm)
set.network.attribute(g,"mygval","boo")
set.vertex.attribute(g,"myvval",letters[1:3])
network.vertex.names(g) <- LETTERS[1:10]

#List the attributes
list.edge.attributes(g)
list.network.attributes(g)
list.vertex.attributes(g)

#Retrieve the attributes
get.edge.attribute(g$mel,"myeval")  #Note the first argument!
get.edge.value(g,"myeval")          #Another way to do this
get.edge.attribute(g$mel,"myeval2") 
get.network.attribute(g,"mygval")
get.vertex.attribute(g,"myvval")
network.vertex.names(g)

#Purge the attributes
delete.edge.attribute(g,"myeval")
delete.edge.attribute(g,"myeval2")
delete.network.attribute(g,"mygval")
delete.vertex.attribute(g,"myvval")

#Verify that the attributes are gone
list.edge.attributes(g)
list.network.attributes(g)
list.vertex.attributes(g)

#Note that we can do similar things using operators
g \%n\% "mygval" <- "boo"               #Set attributes, as above
g \%v\% "myvval" <- letters[1:3]
g \%e\% "myeval" <- mm
g[,,names.eval="myeval"] <- mm          #Another way to do this
g \%n\% "mygval"                        #Retrieve the attributes
g \%v\% "myvval"
g \%e\% "mevval"
as.sociomatrix(g,"myeval")              # Or like this

}
\references{
Butts, C. T.  (2008).  \dQuote{network: a Package for Managing
Relational Data in R.}  \emph{Journal of Statistical Software}, 24(2).
\doi{10.18637/jss.v024.i02}
}
\seealso{
\code{\link{loading.attributes}},\code{\link{network}},
\code{\link{as.network.matrix}}, \code{\link{as.sociomatrix}},
\code{\link{as.matrix.network}}, \code{\link{network.extraction}}
}
\author{
Carter T. Butts \email{buttsc@uci.edu}
}
\keyword{classes}
\keyword{graphs}