-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ Imports: | |
igraph | ||
License: GPL-3 | ||
LazyData: TRUE | ||
RoxygenNote: 5.0.0 | ||
RoxygenNote: 5.0.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(addstates) | ||
export(delete_isolates) | ||
export(get_statespace) | ||
export(lastints) | ||
export(lastnet) | ||
export(rowmatch) | ||
export(stateclass) | ||
export(stateid) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#' Add State ids and classes | ||
#' | ||
#' @param df a dataframe with two variables, winners and losers | ||
#' @return the df with two extra rows containing state id and class | ||
#' @examples | ||
#' df<-data.frame(winner=c(1,2,3,1,2,3,2,1,2,3,3,1,2,3,4,3,1,3,2,1,1,1,1,2,2), | ||
#' loser=c(2,4,4,4,3,2,1,3,3,4,4,2,3,2,3,4,2,4,3,3,3,2,2,4,3) | ||
#' ) | ||
#' addstates(df) | ||
#' @export | ||
|
||
addstates <- function(df){ | ||
v<-lastnet(df) | ||
v1<-lapply(v, get_statespace) | ||
df$id<-unlist(lapply(v1, stateid)) | ||
df$class<-unlist(lapply(v1, stateclass)) | ||
return(df) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#' Delete isolated nodes from network | ||
#' | ||
#' @param q an igraph object | ||
#' @return an igraph object containing only connected nodes | ||
#' @examples | ||
#' g=igraph::graph.edgelist(cbind(a=c(1,2,3,4), b=c(3,1,1,4)),directed=TRUE) | ||
#' delete_isolates(g) | ||
#' @export | ||
|
||
delete_isolates<-function(q){ | ||
igraph::delete.vertices(q,which(igraph::degree(q)==0)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' Match rows of dataframes | ||
#' | ||
#' @param v1 a dataframe or matrix | ||
#' @param v2 a row of a dataframe or matrix or a vector of length equal to ncol(v1) | ||
#' @param nomatch how to represent non matching indices of rows | ||
#' @return a vector with a 1 in the index of matched rows | ||
#' @examples | ||
#' v1 <- data.frame(A=c(1,2,3),B=c(2,3,3),C=c(3,3,2),D=c(1,1,1)) | ||
#' v2 <- data.frame(A=3,B=3,C=2,D=1) | ||
#' rowmatch(v1,v2,nomatch=NA) | ||
#' @export | ||
|
||
|
||
rowmatch<-function (v1, v2, nomatch = NA) | ||
{ | ||
if (class(v2) == "matrix") | ||
v2 <- as.data.frame(v2) | ||
if (is.null(dim(v1))) | ||
v1 <- as.data.frame(matrix(v1, nrow = 1)) | ||
cv1 <- do.call("paste", c(v1[, , drop = FALSE], sep = "\r")) | ||
cv2 <- do.call("paste", c(v2[, , drop = FALSE], sep = "\r")) | ||
match(cv1, cv2, nomatch = nomatch) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#' Find State Class | ||
#' | ||
#' @param x a vector of network characteristics generated by get_statespace function | ||
#' @return the state class corresponding to the network characteristics | ||
#' @examples | ||
#' g=igraph::graph.edgelist(cbind(a=c(1,2,3,3), b=c(4,1,1,2)),directed=TRUE) | ||
#' gs=get_statespace(g) | ||
#' stateclass(gs) | ||
#' @export | ||
|
||
stateclass <- function(x){ | ||
|
||
data("states", envir = environment()) | ||
xx <- get("states", envir = environment()) | ||
|
||
data("stateclasses", envir = environment()) | ||
xxx <- get("stateclasses", envir = environment()) | ||
|
||
q<-rowmatch(xx[1:12], x, nomatch = NA) | ||
q1<-xxx[which(q==1)] | ||
return(q1) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#' State classes of 41 network states | ||
#' | ||
#' Vector defining the classes of 41 network states | ||
#' | ||
#' @format A vector of length 41: | ||
"stateclasses" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#' Find State ID | ||
#' | ||
#' @param x a vector of network characteristics generated by get_statespace function | ||
#' @return the state id corresponding to the network characteristics | ||
#' @examples | ||
#' g=igraph::graph.edgelist(cbind(a=c(1,2,3,3), b=c(4,1,1,2)),directed=TRUE) | ||
#' gs=get_statespace(g) | ||
#' stateid(gs) | ||
#' @export | ||
|
||
stateid <- function(x){ | ||
|
||
data("states", envir = environment()) | ||
xx <- get("states", envir = environment()) | ||
|
||
q<-rowmatch(xx[1:12], x, nomatch = NA) | ||
q1<-which(q==1) | ||
return(q1) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.