how to judge a virable is a integer?

13 messages
Open this post in threaded view
|

how to judge a virable is a integer?

 Dear usRers,    I want to judge virable is or not a integer?   e.g.  is.integer(1)  FALSE   because it is a numeric, but i want it's true. as.integer may not be used. because i don't know a is 1 or 1.1. -- PO SU mail: [hidden email] Majored in Statistics from SJTU ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: how to judge a virable is a integer?

 On 18-10-2014, at 12:41, PO SU <[hidden email]> wrote: > > > Dear usRers, >    I want to judge virable is or not a integer? >   e.g.  is.integer(1)  FALSE   because it is a numeric, but i want it's true. > as.integer may not be used. because i don't know a is 1 or 1.1. > is.integer is surely what you need if you wish to test if a variable is integer. See this # a <- 1 # b <- 1L # is.integer(a) [1] FALSE # is.integer(b) [1] TRUE See the help for is.integer to see how you can test for a wholenumber, which might be what you want. Berend ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: how to judge a virable is a integer?

 But i use a<-10/b ,  b is some value ,may be  5, maybe 5.5  not in the form  xxL ,so how can i do in the situation to judge a ? -- PO SU mail: [hidden email] Majored in Statistics from SJTU At 2014-10-18 18:58:48, "Berend Hasselman" <[hidden email]> wrote: > >On 18-10-2014, at 12:41, PO SU <[hidden email]> wrote: > >> >> >> Dear usRers, >>    I want to judge virable is or not a integer? >>   e.g.  is.integer(1)  FALSE   because it is a numeric, but i want it's true. >> as.integer may not be used. because i don't know a is 1 or 1.1. >> > >is.integer is surely what you need if you wish to test if a variable is integer. >See this > ># a <- 1 ># b <- 1L > ># is.integer(a) >[1] FALSE > ># is.integer(b) >[1] TRUE > >See the help for is.integer to see how you can test for a wholenumber, which might be what you want. > >Berend > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: how to judge a virable is a integer?

 > But i use a<-10/b ,  b is some value ,may be  5, maybe 5.5 If you do floating point arithmetic on integers you'll usually get floating point answers, including the 5.0. See FAQ 7.31 for the usual floating point problem, and ?all.equal for the usual answer to it. You could see if a result is close to an integer by,for example, using all.equal to compare it to itself after rounding. S ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}} ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: how to judge a virable is a integer?

 It's due to that, 1 is a numeric, 1.2 is a numeric, though it's true. but deeply, when i want to know 1 is an integer,  there seems no easy way to get the answer. So, is there anyone happen to know it? -- PO SU mail: [hidden email] Majored in Statistics from SJTU At 2014-10-18 20:10:09, "S Ellison" <[hidden email]> wrote: >> But i use a<-10/b ,  b is some value ,may be  5, maybe 5.5 >If you do floating point arithmetic on integers you'll usually get floating point answers, including the 5.0. > >See FAQ 7.31 for the usual floating point problem, and ?all.equal for the usual answer to it. You could see if a result is close to an integer by,for example, using all.equal to compare it to itself after rounding. > >S > >******************************************************************* >This email and any attachments are confidential. Any use, copying or >disclosure other than by the intended recipient is unauthorised. If >you have received this message in error, please notify the sender >immediately via +44(0)20 8943 7000 or notify [hidden email] >and delete this message and any copies from your computer and network. >LGC Limited. Registered in England 2991879. >Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: how to judge a virable is a integer?

Open this post in threaded view
|

Re: how to judge a virable is a integer?

Open this post in threaded view
|

Re: how to judge a virable is a integer?

Open this post in threaded view
|

Re: how to judge a virable is a integer?

 In reply to this post by PO SU It sounds like you want an 'is.integral' function to tell if a number acts like a mathematical integer, as opposed to 'is.integer', which tells if a number is stored as a 32-bit computer integer.  The test will depend on what properties of mathematical integers you are most interested in.    is.integral <- function (x)  (floor(x) == x) & (abs(x) + 1 > abs(x)) will return TRUE if x has no fractional part and the number's putative successor (predecessor if negative) is different than the number.  That latter test is equivalent (roughly) to log2(abs(x))<53 and comes into play when you run out of bits in the mantissa of a double precision number.  (One might want it to return NA in that case, but I think FALSE works better.) Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, Oct 18, 2014 at 3:41 AM, PO SU <[hidden email]> wrote: > > > Dear usRers, >    I want to judge virable is or not a integer? >   e.g.  is.integer(1)  FALSE   because it is a numeric, but i want it's true. > as.integer may not be used. because i don't know a is 1 or 1.1. > > > > > > -- > > PO SU > mail: [hidden email] > Majored in Statistics from SJTU > ______________________________________________ > [hidden email] 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. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: how to judge a virable is a integer?

Open this post in threaded view
|