Re: [R] Why is 0 not an integer?

2009-08-07 Thread Martin Maechler
...@gmail.com Cc: r-help@r-project.org; daniel.gerl...@geodecapital.com Subject: Re: [R] Why is 0 not an integer? I ran an instant experiment... typeof(0) [1] double typeof(-0) [1] double identical(0, -0) [1] TRUE Best

Re: [R] why is 0 not an integer?

2009-08-06 Thread Kenn Konstabel
- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Steve Jaffe Sent: Wednesday, August 05, 2009 3:16 PM To: r-help@r-project.org Subject: [R] why is 0 not an integer? Why when I assign 0 to an element of an integer vector does the type change

Re: [R] Why is 0 not an integer?

2009-08-06 Thread Gerlanc, Daniel
b/c class(0) [1] numeric typeof(0) [1] double class(0L) [1] integer typeof(0L) [1] integer When you call the : function it always returns an integer sequence, but when you assign a numeric to an element of the vector it gets coerced to the more general type, in this case, numeric. Note

Re: [R] Why is 0 not an integer?

2009-08-06 Thread milton ruser
By the way: Are there difference between -0 and 0? On Thu, Aug 6, 2009 at 5:00 PM, Gerlanc, Daniel daniel.gerl...@geodecapital.com wrote: b/c class(0) [1] numeric typeof(0) [1] double class(0L) [1] integer typeof(0L) [1] integer When you call the : function it always

Re: [R] Why is 0 not an integer?

2009-08-06 Thread Giovanni Petris
I ran an instant experiment... typeof(0) [1] double typeof(-0) [1] double identical(0, -0) [1] TRUE Best, Giovanni By the way: Are there difference between -0 and 0? __ R-help@r-project.org mailing list

Re: [R] Why is 0 not an integer?

2009-08-06 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Giovanni Petris Sent: Thursday, August 06, 2009 3:00 PM To: milton.ru...@gmail.com Cc: r-help@r-project.org; daniel.gerl...@geodecapital.com Subject: Re: [R] Why is 0

[R] why is 0 not an integer?

2009-08-05 Thread Steve Jaffe
Why when I assign 0 to an element of an integer vector does the type change to numeric? Here is a particularly perplexing example: v - 0:10 v [1] 0 1 2 3 4 5 6 7 8 9 10 class(v) [1] integer v[1] - 0 class(v) [1] numeric #!! -- View this message in context:

Re: [R] why is 0 not an integer?

2009-08-05 Thread Nikos Alexandris
On Wed, 2009-08-05 at 13:16 -0700, Steve Jaffe wrote: Why when I assign 0 to an element of an integer vector does the type change to numeric? Here is a particularly perplexing example: v - 0:10 v [1] 0 1 2 3 4 5 6 7 8 9 10 class(v) [1] integer v[1] - 0 try this: v -

Re: [R] why is 0 not an integer?

2009-08-05 Thread Duncan Murdoch
On 8/5/2009 4:16 PM, Steve Jaffe wrote: Why when I assign 0 to an element of an integer vector does the type change to numeric? Because 0 is a numeric constant, not an integer constant. R doesn't check the value, only the type: it's just as if you assigned 3.14159 to that element as far as

Re: [R] why is 0 not an integer?

2009-08-05 Thread Erik Iverson
, August 05, 2009 3:16 PM To: r-help@r-project.org Subject: [R] why is 0 not an integer? Why when I assign 0 to an element of an integer vector does the type change to numeric? Here is a particularly perplexing example: v - 0:10 v [1] 0 1 2 3 4 5 6 7 8 9 10 class(v) [1] integer v[0] - 0

Re: [R] why is 0 not an integer?

2009-08-05 Thread John Kane
Pesumably because v[1] - 0 give a numeric result, then the rest of v is coerced into numeric. Observe v - 0:10 class(v) v[1] - as.integer(0) class(v[1]) class(v) --- On Wed, 8/5/09, Steve Jaffe sja...@riskspan.com wrote: From: Steve Jaffe sja...@riskspan.com Subject: [R] why is 0

Re: [R] why is 0 not an integer?

2009-08-05 Thread jim holtman
try x - 0 class(x) [1] numeric x - 0L class(x) [1] integer You have to explicitly indicate that you want integer. On Wed, Aug 5, 2009 at 4:16 PM, Steve Jaffesja...@riskspan.com wrote: Why when I assign 0 to an element of an integer vector does the type change to numeric? Here is a