Learn R Programming

ernm (version 1.0.4)

extract-methods: Subsetting and assignment for ernm network objects

Description

These methods allow standard subsetting (`[`) and assignment (`[<-`) for `Rcpp_DirectedNet` and `Rcpp_UndirectedNet` objects.

Usage

# S4 method for Rcpp_DirectedNet
[(x, i, j, ..., maskMissing = TRUE, drop = TRUE)

# S4 method for Rcpp_UndirectedNet [(x, i, j, ..., maskMissing = TRUE, drop = TRUE)

# S4 method for Rcpp_DirectedNet [(x, i, j, ...) <- value

# S4 method for Rcpp_UndirectedNet [(x, i, j, ...) <- value

Value

A modified object or extracted submatrix depending on the method.

Arguments

x

an `Rcpp_DirectedNet` or `Rcpp_UndirectedNet` object.

i, j

index vectors.

...

currently unused.

maskMissing

Logical. Should missing values be masked by NA?

drop

Ignored (present for compatibility).

value

Values to assign (for `[<-` only).

Examples

Run this code

# convert the Sampson's monks network into a native ernm network
data(samplike)
sampnet <- as.BinaryNet(samplike)
sampnet

# get the number of nodes and edges in the network
sampnet$size()
sampnet$nEdges()

# Extract and assign vertex attributes
sampnet[["group"]]
sampnet[["newvar"]] <- rnorm(18)
sampnet[["newvar"]]

# get the edge matrix between the first 5 vertices
sampnet[1:5,1:5]

# add an edge 2 --> 3
sampnet[2,3] <- TRUE

# Make the dyad 4 --> 1 missing
sampnet[4,1] <- NA
sampnet[1:5,1:5]

# get the in and out degrees for each vertex
sampnet$inDegree(1:18)
sampnet$outDegree(1:18)

Run the code above in your browser using DataLab