Full_Name: Mauricio Version: 2.9.0 (2009-04-17) OS: i486-pc-linux-gnu Submission from: (NULL) (193.205.203.3) This is a very simple function that seems not to be working, according to the definition given by '?is.integer'. I checked in the Bug Tracking page at http://bugs.R-project.org/, but I didn't find any related message. The possible problem is:> is.integer(1)[1] FALSE and 1 is obviously an integer value. I would really appreciate if you could clarify if this is really a bug or not. Thanks in advance, Mauricio> version_ platform i486-pc-linux-gnu arch i486 os linux-gnu system i486, linux-gnu status major 2 minor 9.0 year 2009 month 04 day 17 svn rev 48333 language R version.string R version 2.9.0 (2009-04-17)
On Wed, Apr 22, 2009 at 10:45 AM, <hzambran.newsgroups at gmail.com> wrote:> Full_Name: Mauricio > Version: 2.9.0 (2009-04-17) > OS: ?i486-pc-linux-gnu > Submission from: (NULL) (193.205.203.3) > > > This is a very simple function that seems not to be working, according to the > definition given by '?is.integer'. > > I checked in the Bug Tracking page at http://bugs.R-project.org/, but I didn't > find any related message. > > The possible problem is: > > >> is.integer(1) > [1] FALSE > > and 1 is obviously an integer value. >Actually it's not:> typeof(1)[1] "double" So the command does work as the help describes. From ?is.integer() "is.integer returns TRUE or FALSE depending on whether its argument is of integer type or not, unless it is a factor when it returns FALSE." In the HTML help "type" is a link to the typeof() function. HTH Peter> > I would really appreciate if you could clarify if this is really a bug or not. > > Thanks in advance, > > Mauricio > >> version > ? ? ? ? ? ? ? _ > platform ? ? ? i486-pc-linux-gnu > arch ? ? ? ? ? i486 > os ? ? ? ? ? ? linux-gnu > system ? ? ? ? i486, linux-gnu > status > major ? ? ? ? ?2 > minor ? ? ? ? ?9.0 > year ? ? ? ? ? 2009 > month ? ? ? ? ?04 > day ? ? ? ? ? ?17 > svn rev ? ? ? ?48333 > language ? ? ? R > version.string R version 2.9.0 (2009-04-17) > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
> typeof(1)[1] "double" 1 is obviously *not* an integer value. Best, Josh -- http://quantemplation.blogspot.com http://www.fosstrading.com On Wed, Apr 22, 2009 at 12:45 PM, <hzambran.newsgroups at gmail.com> wrote:> Full_Name: Mauricio > Version: 2.9.0 (2009-04-17) > OS: ?i486-pc-linux-gnu > Submission from: (NULL) (193.205.203.3) > > > This is a very simple function that seems not to be working, according to the > definition given by '?is.integer'. > > I checked in the Bug Tracking page at http://bugs.R-project.org/, but I didn't > find any related message. > > The possible problem is: > > >> is.integer(1) > [1] FALSE > > and 1 is obviously an integer value. > > > I would really appreciate if you could clarify if this is really a bug or not. > > Thanks in advance, > > Mauricio > >> version > ? ? ? ? ? ? ? _ > platform ? ? ? i486-pc-linux-gnu > arch ? ? ? ? ? i486 > os ? ? ? ? ? ? linux-gnu > system ? ? ? ? i486, linux-gnu > status > major ? ? ? ? ?2 > minor ? ? ? ? ?9.0 > year ? ? ? ? ? 2009 > month ? ? ? ? ?04 > day ? ? ? ? ? ?17 > svn rev ? ? ? ?48333 > language ? ? ? R > version.string R version 2.9.0 (2009-04-17) > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
On Wed, 22 Apr 2009, hzambran.newsgroups at gmail.com wrote:> Full_Name: Mauricio > Version: 2.9.0 (2009-04-17) > OS: i486-pc-linux-gnu > Submission from: (NULL) (193.205.203.3) > > > This is a very simple function that seems not to be working, according to the > definition given by '?is.integer'. > > I checked in the Bug Tracking page at http://bugs.R-project.org/, but I didn't > find any related message. > > The possible problem is: > > >> is.integer(1) > [1] FALSE > > and 1 is obviously an integer value.Obvious? You must know something I do not, as the protagonist of Zen and the Art of Motorcylce Maintenance would have pointed out. And if you do then it is not really obvious.> is.double(1)[1] TRUE 1L _is_ an integer.> is.integer(1L)[1] TRUE>So this is not a bug. Please see the FAQ for advise on not posting non-bugs. Chuck> > > I would really appreciate if you could clarify if this is really a bug or not. > > Thanks in advance, > > Mauricio > >> version > _ > platform i486-pc-linux-gnu > arch i486 > os linux-gnu > system i486, linux-gnu > status > major 2 > minor 9.0 > year 2009 > month 04 > day 17 > svn rev 48333 > language R > version.string R version 2.9.0 (2009-04-17) > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
To the best of my knowledge this is not a bug. According to FAQ 3.3.3 "Numeric constants with no fractional and exponent (i.e., only integer) part are taken as integer in S-Plus 6.x or later, but as double in R." You can see it by invoking>storage.mode(1)[1] "double" Hence, if you really want to have integers, you need to use as.integer i.e.> storage.mode(as.integer(1))[1] "integer" Cheers, Mathieu Le mercredi 22 avril 2009 ? 19:45 +0200, hzambran.newsgroups at gmail.com a ?crit :> Full_Name: Mauricio > Version: 2.9.0 (2009-04-17) > OS: i486-pc-linux-gnu > Submission from: (NULL) (193.205.203.3) > > > This is a very simple function that seems not to be working, according to the > definition given by '?is.integer'. > > I checked in the Bug Tracking page at http://bugs.R-project.org/, but I didn't > find any related message. > > The possible problem is: > > > > is.integer(1) > [1] FALSE > > and 1 is obviously an integer value. > > > I would really appreciate if you could clarify if this is really a bug or not. > > Thanks in advance, > > Mauricio > > > version > _ > platform i486-pc-linux-gnu > arch i486 > os linux-gnu > system i486, linux-gnu > status > major 2 > minor 9.0 > year 2009 > month 04 > day 17 > svn rev 48333 > language R > version.string R version 2.9.0 (2009-04-17) > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- Institute of Mathematics Ecole Polytechnique F?d?rale de Lausanne STAT-IMA-FSB-EPFL, Station 8 CH-1015 Lausanne Switzerland http://stat.epfl.ch/ Tel: + 41 (0)21 693 7907
Dear R experts, You are being a bit harsh on this user. He simply doesn't understand the distinction between "object of type integer" and "integer-valued object", which is actually fairly subtle. On Wed, Apr 22, 2009 at 1:45 PM, <hzambran.newsgroups at gmail.com> wrote:> This is a very simple function that seems not to be working, according to the > definition given by '?is.integer'....>> is.integer(1) > [1] FALSE > > and 1 is obviously an integer value.The is.integer function is correctly documented to check whether objects are of *type* integer, thus: is.integer( 1L ) => TRUE In R, objects of type integer are only created with literals of the form 999L; as the output of some functions when the input is integral (e.g. sort, unique, rev, ...); as the output of some functions which return index values or differences of index values (which, grep, rle, ...); and the output of a few other functions in certain cases (seq). Most numbers in R are floating-point numbers (type double), and determining whether their value is integral is rather subtle. For example, consider the vector 1+1000^-(1:6). In floating-point arithmetic, the first 5 values are distinguishable from the integer 1, but the 6th is not, though of course the *mathematical* number 1+1000^-6 is not integral. Now consider 1e40, which has the property that floor(x)==x==ceiling(x), which you might think characterizes an integer; but it also has the property that x+1 == x. Similarly for 1/3 * 1e40. In other words, it is really a rather subtle question whether a floating-point number "represents" an integer.... -s
is.integer() is one of those functions with a name that can be confusing -- it looks at the underlying storage type of its argument (e.g., integer, floating point, character, etc.) not at the value stored in the argument. So, the type of behavior you see is this: > is.integer(1) [1] FALSE > is.integer(as.integer(1)) [1] TRUE > is.integer(as.integer(1) * 1.0) [1] FALSE > is.integer(as.integer(NA)) [1] TRUE > Careful reading of ?is.integer does tell you this, but I wouldn't accuse that help page of making such information blatantly obvious to new users of R. To test whether a value is an integer value, you can so something like this: > is.wholenumber <- function(x, tolerance = .Machine$double.eps^0.5) return(abs(x - round(x)) < tolerance) > is.wholenumber(1) [1] TRUE > is.wholenumber(seq(1,5,by=0.5)) [1] TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE > The 'tolerance' part is to allow for minor deviations that might be due to floating point representation issues, e.g., on my computer 1/49 * 49 does not result in a value that is exactly equal to 1: > 1/49 * 49 - 1 [1] -1.110223e-16 > is.wholenumber(1/49 * 49) [1] TRUE > is.wholenumber(1/49 * 49, tol=0) [1] FALSE > -- Tony Plate hzambran.newsgroups at gmail.com wrote:> Full_Name: Mauricio > Version: 2.9.0 (2009-04-17) > OS: i486-pc-linux-gnu > Submission from: (NULL) (193.205.203.3) > > > This is a very simple function that seems not to be working, according to the > definition given by '?is.integer'. > > I checked in the Bug Tracking page at http://bugs.R-project.org/, but I didn't > find any related message. > > The possible problem is: > > > >> is.integer(1) >> > [1] FALSE > > and 1 is obviously an integer value. > > > I would really appreciate if you could clarify if this is really a bug or not. > > Thanks in advance, > > Mauricio > > >> version >> > _ > platform i486-pc-linux-gnu > arch i486 > os linux-gnu > system i486, linux-gnu > status > major 2 > minor 9.0 > year 2009 > month 04 > day 17 > svn rev 48333 > language R > version.string R version 2.9.0 (2009-04-17) > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > >
Thanks for the clear answer Stephen and thanks to all the guys that pointed out my misunderstanding about the distinction between object of type integer" and "integer-valued object". I'm sorry for submitting to the R-bugs list something that is very clear for all the members of the list, but it was not clear for me after reading the help, because I was testing if a particular result had a decimal part or not, and it seemed natural to me to use the 'is.integer' function instead of a combination of other operations. Probably, and only if the guys of r-devel deem it necessary, it could be good to add a small example at the end of the 'is.integer' function showing that is.integer(1) is FALSE (or the example mentioned by Martin), which can avoid this misunderstanding to people with less knowledge about storage modes in R. Thank you very much, and in the future I will use R-help or maybe R-devel. Mauricio -- Linux user #454569 -- Ubuntu user #17469
Seemingly Similar Threads
- stringsAsFactors has no impact in expand.grid()?
- relative convergence in 'optim'
- ' --enable-R-shlib' problem when setting up R-devel in Linux Mint 17.1 64-bit
- "cannot allocate vector of size ..." in RHLE5 PAE kernel
- Failing to print mer object in an RData image