s-news
[Top] [All Lists]

Re: identifying which column/row is passed

To: "Schwarz,Paul" <PSchwarz@gcrinsight.com>, s-news@lists.biostat.wustl.edu
Subject: Re: identifying which column/row is passed
From: "Richard M. Heiberger" <rmh@temple.edu>
Date: Fri, 10 Feb 2006 23:01:58 -0500
the easiest way is to do the apply loop over the index.

tmp <- matrix(1:12,3,4)
tmp[2,3] <- 100
tmp[3,2] <- 200
dimnames(tmp) <- list(letters[1:3], LETTERS[1:4])
tmp

sapply(1:3, tmp,
       FUN=function(i, x) {
         x.i <- x[i,,drop=FALSE]
         big <- (x.i > 20)
         j <- seq(length(x.i))[big]
         if (length(j) > 0) cat(i, ",", j, "\n")
         apply(x.i, 1, mean)
       })

apply(tmp, 1, mean)

<Prev in Thread] Current Thread [Next in Thread>
  • Re: identifying which column/row is passed, Richard M. Heiberger <=