On 17-12-2012, at 21:03, Asis Hallab wrote:

> Dear R experts,
> 
> please accept my apologies for the missing information. 
> 
> You need to call sumRows in the following manner:
> 
> sumRows(t, sort( unique( t[,"Domain.Architecture.Distance"] ) ) )
> 
> Thank you Berend and David for pointing out my mistake.
> 

Use this alternative sumRows

sumRows.1 <- function( tbl, ps ) {
 sum(
   sapply(ps,
     function(x) {
       t <- if ( is.na(x) ) {
         tbl[ is.na(tbl[ , "Domain.Architecture.Distance" ] ), ,drop=F]
       } else {
                # explicit check for NA
         tbl[ !is.na(tbl[ , "Domain.Architecture.Distance" ]) & tbl[ , 
"Domain.Architecture.Distance" ] == x , ,drop=F]
       }
       nrow(t)
     }
   )
 )
}

z <- sort( unique( t[,"Domain.Architecture.Distance"] ) )

sumRows(t,z)
sumRows.1(t,z)

You must check with is.na() when not using which.
More insight can be gained by reading the help for Logical operators.
Try

?'!'

and read the bit about NA.
I'm too lazy to check if the modifcation with !is.na completely accounts for 
the difference between  the which and the not which versions.

And please don't use t as an object name.

Berend

______________________________________________
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.

Reply via email to