...@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
-
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
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
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
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
-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
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:
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 -
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
, 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
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
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
12 matches
Mail list logo