Created
April 6, 2013 00:16
-
-
Save pedroj/5323641 to your computer and use it in GitHub Desktop.
Functions to generate adjacency matrix fills
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------------------------------------------------------------- | |
# [Title]: Functions to generate adjacency matrix fills useful in | |
# network analysis. | |
# [Date]: 1 Apr 2013 [Loc]: Sevilla | |
# Pedro Jordano. | |
# ...................................................................... | |
# nullmat will generate a 0 matrix of size m x n. | |
# fullconnmat will generate a fully-connected matrix of size m x n. | |
# randommat will generate a randomly-filled matrix of size m x n. | |
# fullynest will generate a fully-nested matrix of size m x n. | |
# ---------------------------------------------------------------------- | |
## First version DATE 1Apr2013. Revised DATE 5Apr2013 | |
# ---------------------------------------------------------------------- | |
# Null matrix | |
nullmat <- function (m,n) { | |
size=m*n | |
matrix(rep(0,size), nrow=m, ncol=n, byrow = TRUE) | |
} | |
# Fully connected matrix | |
fullconnmat <- function (m,n) { | |
size=m*n | |
matrix(rep(1,size), nrow=m, ncol=n, byrow = TRUE) | |
} | |
# Random matrix | |
randommat <- function (m,n) { | |
size=m*n | |
matrix(sample(c(0,1), size, replace=T), | |
nrow=m, ncol=n, byrow = TRUE) | |
} | |
# Fully nested matrix | |
fullynest <- function (m,n) { | |
x<- as.vector(rep(1,n)) | |
for (i in 1:m) { | |
x <- rbind(x,c(rep(1,n-i), rep(0, i)))} | |
x<-data.frame(x,row.names=NULL) | |
x[-(m+1), ] | |
} | |
# ---------------------------------------------------------------------- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment