First, this has nothing to do with "0". Assigning 1000 to an element of v would also have this effect. Two, the first element of a vector is indexed by "1", not "0". While what you wrote isn't a syntax error (v[0] <- 0), it may be not doing what you think, but I don't know.
Finally, the answer to your question. Try typing class(0) to see that it is in fact numeric. So you may want v[1] <- as.integer(0) to get what you are expecting. HTH. -----Original Message----- 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 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 > class(v) [1] "numeric" #!! > -- View this message in context: http://www.nabble.com/why-is-0-not-an-integer--tp24835423p24835423.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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. ______________________________________________ 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.