[R] Access only part of last dimension of table/matrix

David Winsemius dwinsemius at comcast.net
Fri Jul 1 23:50:04 CEST 2011


I would like to do some operations inside a function using only one  
value for the last dimension of a table/matrix:

  tabfn <- function (dfrm, facvec, YN ="event"){
              return( Etbl <- do.call(table, dfrm[ , c(facvec,  
"event") ]) )
               # just want Etbl[,,,"TRUE"] or Etbl[,, "TRUE"] or  
Etbl[,"TRUE"]
               }
  tbl <- tabfn(testdf, c("x", "y") )
  tbl   # all value of event returned

At the console it is easy for me to count the number of factors and  
use the right number of commas

tbl[ , , "TRUE"] if I only want the slice with that value. How can I  
do this programmatically?

Thnks.

-- 
David.


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list