[R] rowSums() and is.integer()

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Nov 10 08:32:05 CET 2007


On Fri, 9 Nov 2007, Robin Hankin wrote:

> Hi
>
> [R-2.6.0, macOSX 10.4.10].
>
> The helppage says that rowSums() and colSums()
> are equivalent to 'apply' with  'FUN = sum'.
>
> But I came across this:
>
> > a <- matrix(1:30,5,6)
> > is.integer(apply(a,1,sum))
> [1] TRUE
> > is.integer(rowSums(a))
> [1] FALSE
> >

'equivalent' does not mean 'identical': the wording was deliberate.

> so rowSums() returns a float.

And that is what the help page says it does (albeit more accurately: there 
is no 'float' type, but there is numeric aka double and the result could 
be complex).

> Why is this?

You seem to be asking why R works as documented!

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list