[Mattice-commits] r83 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Dec 12 22:50:24 CET 2008
Author: andrew_hipp
Date: 2008-12-12 22:50:24 +0100 (Fri, 12 Dec 2008)
New Revision: 83
Modified:
pkg/R/regimes.R
Log:
first shot at a recursive regimeMatrix, but doesn't work
Modified: pkg/R/regimes.R
===================================================================
--- pkg/R/regimes.R 2008-12-12 07:02:23 UTC (rev 82)
+++ pkg/R/regimes.R 2008-12-12 21:50:24 UTC (rev 83)
@@ -150,15 +150,19 @@
return(outmatrix)
}
-#regMatRec <- function(n, maxNodes, dat) {
-# for (i in 1:n) {
-# place a 1 in the ith position
-# temp = regMatRec on the zeros, thus with n = n-1, maxNodes = maxNodes - 1
-# make a matrix of the results, with the temp and the ith-position 1 concatenated
-# }
-# make an all-zero row
-# return results
-#}
+regMatRec <- function(n, maxNodes) {
+## not working correctly with maxNodes > 1
+ outmat <- matrix(NA, nrow = 0, ncol = n)
+ for (i in 1:(n-1)) {
+ temp <- numeric(n)
+ temp[1:i] <- c(rep(0, (i-1)), 1)
+ if (maxNodes > 1) temp[(i+1):n] <- regMatRec(n - 1, maxNodes - 1)
+ else temp[(i+1):n] <- rep(0, length((i+1):n))
+ outmat <- rbind(outmat, temp)
+ }
+ outmat <- rbind(outmat, c(rep(0, n-1), 1))
+ return(outmat)
+}
as.binary <- function(n, base = 2, r = FALSE, digits = NULL)
More information about the Mattice-commits
mailing list