Dear usRers, ? Now i want to cal ,e.g. ?cal(1.234)? will get 3 ?cal(1) will get 0 ?cal(1.3045) will get 4 ?But the difficult part is cal(1.3450) will get 4 not 3. So, is there anyone happen to know the solution to this problem, or it can't be solved in R, because 1.340 will always be transformed autolly to 1.34? -- PO SU mail: desolator88 at 163.com Majored in Statistics from SJTU
I am baffled. I think those were English words but they didn't make any sense to me. Not was there a reproducible example to turn to. Can you try again? --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On October 23, 2014 8:35:06 PM PDT, PO SU <rhelpmaillist at 163.com> wrote:> >Dear usRers, >? Now i want to cal ,e.g. >?cal(1.234)? will get 3 >?cal(1) will get 0 >?cal(1.3045) will get 4 >?But the difficult part is cal(1.3450) will get 4 not 3. >So, is there anyone happen to know the solution to this problem, or it >can't be solved in R, because 1.340 will always be transformed autolly >to 1.34? > > > > > > >-- > >PO SU >mail: desolator88 at 163.com >Majored in Statistics from SJTU >______________________________________________ >R-help at 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.
On 23/10/2014, 11:35 PM, PO SU wrote:> > Dear usRers, > Now i want to cal ,e.g. > cal(1.234) will get 3 > cal(1) will get 0 > cal(1.3045) will get 4 > But the difficult part is cal(1.3450) will get 4 not 3. > So, is there anyone happen to know the solution to this problem, or it can't be solved in R, because 1.340 will always be transformed autolly to 1.34? >No, there's no way to do what you want unless you put quotes around the number. R parses 1.345 and 1.3450 as exactly the same thing, whereas "1.345" and "1.3450" are different. Duncan Murdoch
Where do these numbers come from? If they are calculated values, they are actually many decimal places longer than your examples. They are represented on your terminal with fewer decimals according to the setting of options("digits"). For example:> sqrt(2)*sqrt(2)[1] 2> sqrt(2)*sqrt(2) == 2[1] FALSE # FAQ 7.31 Why doesn?t R think these numbers are equal?> options("digits")$digits [1] 7> options(digits=22) > sqrt(2)*sqrt(2)[1] 2.000000000000000444089 If the numbers were read from a plain text file and you are talking about how they are represented in the file, analyze them as character strings. ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of PO SU Sent: Thursday, October 23, 2014 10:35 PM To: R. Help Subject: [R] how to calculate a numeric's digits count? Dear usRers, ? Now i want to cal ,e.g. ?cal(1.234)? will get 3 ?cal(1) will get 0 ?cal(1.3045) will get 4 ?But the difficult part is cal(1.3450) will get 4 not 3. So, is there anyone happen to know the solution to this problem, or it can't be solved in R, because 1.340 will always be transformed autolly to 1.34? -- PO SU mail: desolator88 at 163.com Majored in Statistics from SJTU ______________________________________________ R-help at 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.