Access and assign (replace) elements from the adjacency matrices or the vertex attributes data frames.
## S3 method for class 'diffnet'x[[name, as.df =FALSE]]## S3 replacement method for class 'diffnet'x[[i, j]]<- value
## S3 method for class 'diffnet'x[i, j, k, drop =FALSE]## S3 replacement method for class 'diffnet'x[i, j, k]<- value
Arguments
x: A diffnet class object.
name: String vector. Names of the vertices attributes.
as.df: Logical scalar. When TRUE returns a data frame, otherwise a list of length T.
i: Index of the i-th row of the adjacency matrix (see details).
j: Index of the j-th column of the adjacency matrix (see details)
value: Value to assign (see details)
k: Index of the k-th slice of the adjacency matrix (see details).
drop: Logical scalar. When TRUE returns an adjacency matrix, otherwise a filtered diffnet object.
Returns
In the case of the assigning methods, a diffnet object. Otherwise, for [[.diffnet a vector extracted from one of the attributes data frames, and for [.diffnet a list of length length(k) with the corresponding [i,j] elements from the adjacency matrix.
Details
The [[.diffnet methods provides access to the diffnet attributes data frames, static and dynamic. By providing the name of the corresponding attribute, depending on whether it is static or dynamic the function will return either a data frame--static attributes--or a list of these--dynamic attributes. For the assigning method, [[<-.diffnet, the function will infer what kind of attribute is by analyzing the dimensions of value, in particular we have the following possible cases:
Class
Dimension
Inferred
matrix
n∗T
Dynamic
matrix
n∗1
Static
matrix
(n∗T)∗1
Dynamic
data.frame
n∗T
Dynamic
data.frame
n∗1
Static
data.frame
(n∗T)∗1
Dynamic
vector
n
Static
vector
n∗T
Dynamic
list *
T data.frames/matrices/vectors
Dynamic
*: With n∗1data.frame/matrix or n length vector.
Other cases will return with error.
In the case of the slices index k, either an integer vector with the positions, a character vector with the labels of the time periods or a logical vector of length T can be used to specify which slices to retrieve. Likewise, indexing vertices works in the same way with the only difference that, instead of time period labels and a logical vector of length T, vertices ids labels and a logical vector of length n
should be provided.
When subsetting slices, the function modifies the toa vector as well as the adopt and cumadopt matrices collapsing network tinmming. For example, if a network goes from time 1 to 20 and we set k=3:10, all individuals who adopted prior to time 3 will be set as adopters at time 3, and all individuals who adopted after time 10 will be set as adopters at time 10, changing the adoption and cumulative adoption matrices. Importantly, k have no gaps, and it should be within the graph time period range.
Examples
# Creating a random diffusion network ---------------------------------------set.seed(111)graph <- rdiffnet(50,4)# Accessing to a static attributegraph[["real_threshold"]]# Accessing to subsets of the adjacency matrixgraph[1,,1:3, drop=TRUE]graph[,,1:3, drop=TRUE][[1]]# ... Now, as diffnet objects (the default)graph[1,,1:3, drop=FALSE]graph[,,1:3, drop=FALSE]# Changing values in the adjacency matrixgraph[1,,, drop=TRUE]graph[1,,]<--5graph[1,,, drop=TRUE]# Adding attributes (dynamic) -----------------------------------------------# Preparing the dataset.seed(1122)x <- rdiffnet(30,4, seed.p.adopt=.15)# Calculating exposure, and storing it diffeexpoM <- exposure(x)expoL <- lapply(seq_len(x$meta$nper),function(x) expoM[,x,drop=FALSE])expoD <- do.call(rbind, expoL)# Adding data (all these are equivalent)x[["expoM"]]<- expoM
x[["expoL"]]<- expoL
x[["expoD"]]<- expoD
# Lets compareidentical(x[["expoM"]], x[["expoL"]])# TRUEidentical(x[["expoM"]], x[["expoD"]])# TRUE
See Also
Other diffnet methods: %*%(), as.array.diffnet(), c.diffnet(), diffnet-arithmetic, diffnet-class, plot.diffnet(), summary.diffnet()