Description Usage Arguments Details Value Author(s) References See Also Examples
The as.matrix
methods attempt to coerce their input to a matrix in adjacency, incidence, or edgelist form. Edge values (from a stored attribute) may be used if present.
1 2 3 4 5 6 7 8 9 10 | ## S3 method for class 'network'
as.matrix(x, matrix.type = NULL, attrname = NULL, ...)
## S3 method for class 'adjacency'
as.matrix.network(x, attrname=NULL,
expand.bipartite = FALSE, ...)
## S3 method for class 'edgelist'
as.matrix.network(x, attrname=NULL,
as.sna.edgelist = FALSE, ...)
## S3 method for class 'incidence'
as.matrix.network(x, attrname=NULL, ...)
|
x |
an object of class |
matrix.type |
one of |
attrname |
optionally, the name of an edge attribute to use for edge values |
expand.bipartite |
logical; if |
as.sna.edgelist |
logical; should the edgelist be returned in sna edglist form? |
... |
additional arguments. |
If no matrix type is specified, which.matrix.type
will be used to make an educated guess based on the shape of x
. Where edge values are not specified, a dichotomous matrix will be assumed.
Edgelists returned by these methods are by default in a slightly different form from the sna
edgelist standard, but do contain the sna
extended matrix attributes (see as.network.matrix
). They should typically be compatible with sna
library functions. To ensure compatibility, the as.sna.edgelist
argument can be set (which returns an exact sna
edgelist). The as.edgelist
function also returns a similar edgelist matrix but with an enforced sorting.
If the attrname
attribute is used to include a charcter attribute, the resulting edgelist matrix will be character rather than numeric.
Note that adjacency matrices may also be obtained using the extraction operator. See the relevant man page for details.
An adjacency, incidence, or edgelist matrix
Carter T. Butts buttsc@uci.edu and David Hunter dhunter@stat.psu.edu
Butts, C. T. (2008). “network: a Package for Managing Relational Data in R.” Journal of Statistical Software, 24(2). http://www.jstatsoft.org/v24/i02/
which.matrix.type
, network
, network.extraction
,as.edgelist
1 2 3 4 5 6 7 8 9 10 11 12 13 | #Create a random network
m <- matrix(rbinom(25,1,0.5),5,5)
diag(m) <- 0
g <- network(m)
#Coerce to matrix form
as.matrix.network(g,matrix.type="adjacency")
as.matrix.network(g,matrix.type="incidence")
as.matrix.network(g,matrix.type="edgelist")
#Can also use the extraction operator
g[,] #Get entire adjacency matrix
g[1:5,6:10] #Obtain a submatrix
|
network: Classes for Relational Data
Version 1.15 created on 2019-04-01.
copyright (c) 2005, Carter T. Butts, University of California-Irvine
Mark S. Handcock, University of California -- Los Angeles
David R. Hunter, Penn State University
Martina Morris, University of Washington
Skye Bender-deMoll, University of Washington
For citation information, type citation("network").
Type help("network-package") to get started.
1 2 3 4 5
1 0 0 0 1 1
2 1 0 0 0 0
3 0 1 0 1 1
4 0 0 1 0 0
5 0 1 1 1 0
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 1 0 0 0 0 -1 0 0 -1 0
[2,] -1 1 1 0 0 0 0 0 0 0
[3,] 0 -1 0 1 1 0 -1 0 0 -1
[4,] 0 0 0 -1 0 1 1 1 0 0
[5,] 0 0 -1 0 -1 0 0 -1 1 1
[,1] [,2]
[1,] 2 1
[2,] 3 2
[3,] 5 2
[4,] 4 3
[5,] 5 3
[6,] 1 4
[7,] 3 4
[8,] 5 4
[9,] 1 5
[10,] 3 5
attr(,"n")
[1] 5
attr(,"vnames")
[1] 1 2 3 4 5
1 2 3 4 5
1 0 0 0 1 1
2 1 0 0 0 0
3 0 1 0 1 1
4 0 0 1 0 0
5 0 1 1 1 0
<NA> <NA> <NA> <NA> <NA>
1 NA NA NA NA NA
2 NA NA NA NA NA
3 NA NA NA NA NA
4 NA NA NA NA NA
5 NA NA NA NA NA
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.