On Wed, Aug 5, 2009 at 11:28 PM, Erik Iverson <eiver...@nmdp.org> wrote:
> 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. According to R Language Definition, foo[0] always returns an empty vector. No idea why this is useful but it is a bit confusing that one can actually assign to foo[0] (and even foo[NULL] ) with some effect: foo <- 1:10 class(foo) # integer foo[NULL] <- "une souris verte" foo # all the same numbers there class(foo) # changed to character!! k > > 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. > [[alternative HTML version deleted]] ______________________________________________ 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.