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 R is concerned.

If you want the integer constant use 0L.

Duncan Murdoch

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"  #!!



______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to