Skip to content
Prev 12239 / 398502 Next

transitions in R

transitions <- function(vect, t1, t2) {
  # vect is the vector to test
  # t1 is the vector of all initial states of the transitions
  # t2 is the vector of all final states of the transitions
  n <- length(vect)
  nt <- length(t1)   # rem: t2 must be same length, not tested here
  v <- rep(vect, nt)
  dim(v) <- c(n, nt)
  v <- t(v)
  tests <- (v[, 1:(n-1)]==t1 & v[, 2:n]==t2)
  res <- apply(tests, 1, "sum", na.rm=T)
  res
}
[1] 1 2 1 2 0 1


...........]<(({?<...............<?}))><...............................
 ) ) ) ) )	 __               	 __
( ( ( ( ( 	|__)              	|  _
 ) ) ) ) )	|   hilippe       	|__)rosjean
( ( ( ( ( 	Marine Biol. Lab., ULB, Belgium
 ) ) ) ) )	                  	 __
( ( ( ( ( 	|\  /|            	|__)
 ) ) ) ) )	| \/ |ariculture &	|__)iostatistics
( ( ( ( ( 
 ) ) ) ) )	e-mail: phgrosje at ulb.ac.be or phgrosjean at sciviews.org
( ( ( ( ( 	SciViews project coordinator (http://www.sciviews.org)
 ) ) ) ) )      tel: 00-32-2-650.29.70 (lab), 00-32-2-673.31.33 (home)
( ( ( ( (
 ) ) ) ) )      "I'm 100% confident that p is between 0 and 1" 
( ( ( ( (                                  L. Gonick & W. Smith (1993) 
 ) ) ) ) )
.......................................................................
 
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._