Re: [Rd] prod(numeric(0)) surprise

2006-01-09 Thread Tony Plate
Since the virtue and reliability of Wikis was brought up, I created a R Wiki page for this at http://www.sciviews.org/_rgui/wiki/doku.php?id=beginners:surprises:emptysetfuncs :-) Anyone: please correct errors and improve it! Tony Plate Duncan Murdoch wrote: > On 1/9/2006 1:27 PM, Liaw, Andy wr

Re: [Rd] prod(numeric(0)) surprise

2006-01-09 Thread Simon Urbanek
On Jan 9, 2006, at 3:35 PM, Kjetil Halvorsen wrote: > But this thread seems to have pointed to some inconsistencies: > >> cumprod( numeric(0) ) > numeric(0) >> cumsum( numeric(0) ) > numeric(0) > > shouldn't this give the same as prod() and sum() in this case? No - as Thomas explained very nicely

Re: [Rd] prod(numeric(0)) surprise

2006-01-09 Thread Kjetil Halvorsen
But this thread seems to have pointed to some inconsistencies: > cumprod( numeric(0) ) numeric(0) > cumsum( numeric(0) ) numeric(0) shouldn't this give the same as prod() and sum() in this case? Same with cummin() and cummax(). Kjetil On 1/9/06, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > > On

Re: [Rd] prod(numeric(0)) surprise

2006-01-09 Thread Prof Brian Ripley
On Mon, 9 Jan 2006, Thomas Lumley wrote: > On Mon, 9 Jan 2006, Martin Morgan wrote: > >> I guess I have to say yes, I'd exepct >> >> x <- 1:10 >> sum(x[x>10]) ==> numeric(0) >> >> this would be reinforced by recongnizing that numeric(0) is not zero, >> but nothing. I guess the summation over an

Re: [Rd] prod(numeric(0)) surprise

2006-01-09 Thread Thomas Lumley
On Mon, 9 Jan 2006, Martin Morgan wrote: > I guess I have to say yes, I'd exepct > > x <- 1:10 > sum(x[x>10]) ==> numeric(0) > > this would be reinforced by recongnizing that numeric(0) is not zero, > but nothing. I guess the summation over an empty set is an empty set, > rather than a set contain

Re: [Rd] prod(numeric(0)) surprise

2006-01-09 Thread Martin Morgan
Duncan Murdoch <[EMAIL PROTECTED]> writes: > On 1/9/2006 1:27 PM, Liaw, Andy wrote: >> If you haven't seen this in your math courses, perhaps this would help: >> http://en.wikipedia.org/wiki/Empty_set >> > > This is what is so great about Wikipedia: it gives certainty where > I'd only call it a f

Re: [Rd] prod(numeric(0)) surprise

2006-01-09 Thread Duncan Murdoch
On 1/9/2006 1:27 PM, Liaw, Andy wrote: > If you haven't seen this in your math courses, perhaps this would help: > > http://en.wikipedia.org/wiki/Empty_set > This is what is so great about Wikipedia: it gives certainty where I'd only call it a fairly standard convention. ;-) Duncan Murdoch

Re: [Rd] prod(numeric(0)) surprise

2006-01-09 Thread Liaw, Andy
If you haven't seen this in your math courses, perhaps this would help: http://en.wikipedia.org/wiki/Empty_set which says, in part: Operations on the empty set Operations performed on the empty set (as a set of things to be operated upon) can also be confusing. (Such operations are nullary oper

Re: [Rd] prod(numeric(0)) surprise

2006-01-09 Thread Martin Morgan
I guess I have to say yes, I'd exepct x <- 1:10 sum(x[x>10]) ==> numeric(0) this would be reinforced by recongnizing that numeric(0) is not zero, but nothing. I guess the summation over an empty set is an empty set, rather than a set containing the number 0. Certainly these exp(x[x>10]) ==> nume

Re: [Rd] prod(numeric(0)) surprise

2006-01-09 Thread Gabor Grothendieck
The way to think about it is: prod(rep(x,n)) == x^n and that works for n=0 too. On 1/9/06, Martin Morgan <[EMAIL PROTECTED]> wrote: > I'm a little confused. I understand that numeric(0) means an empty > numeric vector, not the number 0 expressed as numeric. As it is now, > prod(numeric(0)) ge

Re: [Rd] prod(numeric(0)) surprise

2006-01-09 Thread Duncan Murdoch
On 1/9/2006 12:40 PM, Martin Morgan wrote: > I'm a little confused. I understand that numeric(0) means an empty > numeric vector, not the number 0 expressed as numeric. As it is now, > prod(numeric(0)) generates something -- a vector of length 1 > containing the number 1 -- from nothing. I would ha

Re: [Rd] prod(numeric(0)) surprise

2006-01-09 Thread Martin Morgan
I'm a little confused. I understand that numeric(0) means an empty numeric vector, not the number 0 expressed as numeric. As it is now, prod(numeric(0)) generates something -- a vector of length 1 containing the number 1 -- from nothing. I would have expected prod(numeric(0)) ==> numeric(0) this

Re: [Rd] prod(numeric(0)) surprise

2006-01-08 Thread Martin Maechler
> "Ben" == Ben Bolker <[EMAIL PROTECTED]> > on Sun, 08 Jan 2006 21:40:05 -0500 writes: Ben> Duncan Murdoch wrote: >> On 1/8/2006 9:24 PM, Ben Bolker wrote: >> >>> It surprised me that prod(numeric(0)) is 1. I guess if >>> you say (operation(nothing) == identity el

Re: [Rd] prod(numeric(0)) surprise

2006-01-08 Thread Ben Bolker
Duncan Murdoch wrote: > On 1/8/2006 9:24 PM, Ben Bolker wrote: > >>It surprised me that prod(numeric(0)) is 1. >> I guess if you say (operation(nothing) == identity >> element) this makes sense, but ?? > > > What value were you expecting, or were you expecting an error? I can't > think how

Re: [Rd] prod(numeric(0)) surprise

2006-01-08 Thread Duncan Murdoch
On 1/8/2006 9:24 PM, Ben Bolker wrote: >It surprised me that prod(numeric(0)) is 1. > I guess if you say (operation(nothing) == identity > element) this makes sense, but ?? What value were you expecting, or were you expecting an error? I can't think how any other value could be justified, an

[Rd] prod(numeric(0)) surprise

2006-01-08 Thread Ben Bolker
It surprised me that prod(numeric(0)) is 1. I guess if you say (operation(nothing) == identity element) this makes sense, but ?? Looking in the code, this makes sense: basically (s=1; for i=0 to length(x), multiply s by x[i]) -- which comes out to 1. What *should* prod(numeric(0)) prod