From ripley at stats.ox.ac.uk  Sat Mar 22 07:33:54 2003
From: ripley at stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Sat Mar 22 08:34:07 2003
Subject: [Rd] cumprod doesn't work with data frames (PR#2667)
In-Reply-To: <200303220041.h2M0fhn9023593@pubhealth.ku.dk>
Message-ID: <Pine.LNX.4.44.0303220729180.5299-100000@gannet.stats>

A data frame is not numerical: it can contain character, factor, list and
other variables.  It is `list-like'.  cumprod works column by column
via the group generic functions:

> xx <- data.frame(a=1:5, b=rep(1,5))
> xx
  a b
1 1 1
2 2 1
3 3 1
4 4 1
5 5 1
> cumprod(xx)
    a b
1   1 1
2   2 1
3   6 1
4  24 1
5 120 1

as intended.  See ?Arith (and there are data.frame methods for the Arith 
group generic).

In short; not a bug.

On Sat, 22 Mar 2003 jsisk1@pacbell.net wrote:

> Full_Name: J. Sisk
> Version: 1.6.1
> OS: Linux (RedHat 8)
> Submission from: (NULL) (67.119.41.66)
> 
> 
> Suppose you make a data-frame like so:
> 
>     xxx <- data.frame(a=10,b=20,c=30,d=40)
> 
> Then 
> 
>     cumprod(xxx[1,]) 
> 
> returns 
> 
> > cumprod(xxx[1,])
>    a  b  c  d
> 1 10 20 30 40
> 
> The documentation for cumprod says that it should work on "numerical objects",
> and this is a data-frame, but it seems like it ought to "do the right thing" in
> this case.  If this is redundant, my apologies.

-- 
Brian D. Ripley,                  ripley@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


[Rd] cumprod doesn't work with data frames (PR#2667)
ripley@stats.ox.ac.uk