Dear R community, I have a medium sized matrix stored in variable "t" and a simple function " countRows" (see below) to count the number of rows in which a selected column "C" matches a given value. If I count all rows matching all pairwise distinct values in the column "C" and sum these counts up, I get the number or rows of "t". If I delete the "which" calls from function "countRows" the resulting sum of matching row numbers is much greater than the number of rows in "t".
The table "t" I use can be downloaded from here: https://github.com/groupschoof/PhyloFun/archive/test_selector.zip Unzip the file and read in the table "t" using t <- read.table("test.tbl") The above function "sumRows" is defined as follows: sumRows <- function( tbl, ps ) { sum( sapply(ps, function(x) { t <- if ( is.na(x) ) { tbl[ which( is.na(tbl[ , "Domain.Architecture.Distance" ]) ), , drop=F] } else { tbl[ which( tbl[ , "Domain.Architecture.Distance" ] == x ), , drop=F] } nrow(t) } ) ) } What does cause the different behavior of sumRows, when the which calls are deleted? What does which do, I seem not to grasp? Or is there an error in my test.tbl? * * Any help on this subject will be greatly appreciated. Kind regards and *merry christmas*! [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.