attribute.methods {network}R Documentation

Attribute Interface Methods for the Network Class

Description

These methods get, set, list, and delete attributes at the network, edge, and vertex level.

Usage

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

get.edge.attribute(el, attrname, unlist = TRUE)
get.edge.value(x, attrname, unlist = TRUE)
get.network.attribute(x, attrname, unlist = FALSE)
get.vertex.attribute(x, attrname, na.omit = FALSE, null.na = TRUE,
    unlist = TRUE)
network.vertex.names(x)

list.network.attributes(x)
list.edge.attributes(x)
list.vertex.attributes(x)

set.edge.attribute(x, attrname, value, e=1:length(x$mel))
set.edge.value(x, attrname, value, e=1:length(x$mel))
set.network.attribute(x, attrname, value)
set.vertex.attribute(x, attrname, value, v=1:network.size(x))

Arguments

el a list of edges (possibly network$mel).
x an object of class network.
attrname the name of the attribute to get or set.
unlist logical; should retrieved attributes be unlisted prior to being returned?
na.omit logical; should values from missing vertices/edges be removed?
null.na logical; should NULL values be replaced with NAs?
value values of the attribute to be set; these should be in vector or list form for the edge and vertex cases, or matrix form for set.edge.value.
e IDs for the edges whose attributes are to be altered.
v IDs for the vertices whose attributes are to be altered.

Details

The 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 get.attribute functions look for an edge, network, or vertex attribute (respectively) with the name attrname, returning its values. Note that, to retrieve an edge attribute from all edges within a network x, x$mel should be used as the first argument to get.edge.attribute; get.edge.value is a convenience function which does this automatically. network.vertex.names is a convenience function to extract the "vertex.names" attribute from all vertices.

The set.attribute functions allow one to set the values of edge, network, or vertex attributes. set.edge.value is a convenience function which allows edge attributes to be given in adjacency matrix form. The delete.attribute functions are actually front-ends to their respective set.attribute functions, which set the designated attribute to NULL (thereby deleting it).

Value

For the list.attributes methods, a vector containing attribute names. For the get.attribute methods, a list containing the values of the attribute in question (or simply the value itself, for get.network.attribute). For the set.attribute and delete.attribute methods, the updated network object.

Author(s)

Carter T. Butts buttsc@uci.edu

References

Butts, C.T. 2002. ``Memory Structures for Relational Data in R: Classes and Interfaces'' Working Paper.

See Also

network, as.network.matrix

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)

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

#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")

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

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

[Package network version 0.5-4 Index]