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.

Kind regards and again:
Your help is very much appreciated!




2012/12/17 Berend Hasselman <b...@xs4all.nl>

>
> On 17-12-2012, at 20:22, Asis Hallab wrote:
>
> > 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)
> >      }
> >    )
> >  )
> > }
> >
>
> And how are we supposed to call sumRows()?
>
> sumRows(???, ???
>
> Berend
>
>
>

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

Reply via email to