Re: [R] number of decimal places in a number?

2012-07-10 Thread Martin Ivanov
of the resolution, that is max-min=ineger*resolution. The bbox limits must just be rounded to the same number of digits as the resolution and include all available values, of course. Best regards. Оригинално писмо От: arun Относно: Re: [R] number of decimal places

Re: [R] number of decimal places in a number?

2012-07-09 Thread S Ellison
-Original Message- From: Martin Ivanov I have the longitudes (lon) and latitudes (lat), and I have a resolution (r), for example r = 0.004. The bounding box must have the same number of digits as resolution. Surely the issue is not the particular numeric resolution of the

Re: [R] number of decimal places in a number?

2012-07-09 Thread Jim Plante
,digits=35)) [1] FALSE A.K. - Original Message - From: Petr Savicky savi...@cs.cas.cz To: r-help@r-project.org Cc: Sent: Sunday, July 8, 2012 2:21 PM Subject: Re: [R] number of decimal places in a number? On Sat, Jul 07, 2012 at 01:12:34PM +0100, Ted Harding wrote: I had

Re: [R] number of decimal places in a number?

2012-07-09 Thread Petr Savicky
On Mon, Jul 09, 2012 at 07:52:18AM -0500, Jim Plante wrote: I don't know how significant this is, but WolframAlpha's value of pi disagrees with R's at about the 16th decimal: Wpi-3.141592653589793238462643383279502884197169399375105 ..^

Re: [R] number of decimal places in a number?

2012-07-08 Thread Petr Savicky
On Sat, Jul 07, 2012 at 01:12:34PM +0100, Ted Harding wrote: I had thought of also (as well as my numerical routing) suggesting a gsub() type solution like Joshua's below, but held back because the result could depend on how the number arose (keyboard input, file input, or from computation

Re: [R] number of decimal places in a number?

2012-07-08 Thread Petr Savicky
On Sun, Jul 08, 2012 at 11:39:22AM -0700, arun wrote: Hi Petr, I think sprintf and formatC are identical as it can round 22 decimal places as opposed to print and signif print(pi,digits=35) Hi Arun: Thank you for pointing this out. Funtion formatC() is easier to use and uses the same C

Re: [R] number of decimal places in a number?

2012-07-08 Thread Petr Savicky
On Sat, Jul 07, 2012 at 11:52:35AM +0300, Martin Ivanov wrote: Dear R users, I need a function that gets a number and returns its number of actual decimal places. For example f(3.14) should return 2, f(3.142) should return 3, f(3.1400) should also return 2 and so on. Is such function

Re: [R] number of decimal places in a number?

2012-07-08 Thread arun
: [R] number of decimal places in a number? On Sat, Jul 07, 2012 at 01:12:34PM +0100, Ted Harding wrote: I had thought of also (as well as my numerical routing) suggesting a gsub() type solution like Joshua's below, but held back because the result could depend on how the number arose (keyboard

[R] number of decimal places in a number?

2012-07-07 Thread Martin Ivanov
Dear R users, I need a function that gets a number and returns its number of actual decimal places. For example f(3.14) should return 2, f(3.142) should return 3, f(3.1400) should also return 2 and so on. Is such function already available in R? If not, could you give me a hint how to achieve

Re: [R] number of decimal places in a number?

2012-07-07 Thread Ted Harding
On 07-Jul-2012 08:52:35 Martin Ivanov wrote: Dear R users, I need a function that gets a number and returns its number of actual decimal places. For example f(3.14) should return 2, f(3.142) should return 3, f(3.1400) should also return 2 and so on. Is such function already available in

Re: [R] number of decimal places in a number?

2012-07-07 Thread Joshua Wiley
Hi Martin, Ted is spot on about the binary representation. A very different approach from his would be to convert to character and use regular expressions: ## the example numbers in a vector x - c(3.14, 3.142, 3.1400, 123456.123456789, 123456789.123456789, pi, sqrt(2))

Re: [R] number of decimal places in a number?

2012-07-07 Thread Ted Harding
I had thought of also (as well as my numerical routing) suggesting a gsub() type solution like Joshua's below, but held back because the result could depend on how the number arose (keyboard input, file input, or from computation within R). However, I now also realise that (again because of

Re: [R] number of decimal places in a number?

2012-07-07 Thread Martin Ivanov
Dear Mr Harding, Thank You very much for Your responsiveness. There would seem to be no clean general solution to this question. An important issue would be: What use do you want to put the result to? I need this trick for the following task. I am writing a function which has to determine

Re: [R] number of decimal places in a number?

2012-07-07 Thread arun
using as.character. A.K. - Original Message - From: ted.hard...@wlandres.net ted.hard...@wlandres.net To: r-help@r-project.org Cc: Martin Ivanov tra...@abv.bg Sent: Saturday, July 7, 2012 8:12 AM Subject: Re: [R] number of decimal places in a number? I had thought of also (as well as my

Re: [R] number of decimal places in a number?

2012-07-07 Thread Bert Gunter
mod Ted's comments, I believe that for your situation (not too many digits to represent, decimal point always present) countDecDigits - function(x)nchar(sapply(strsplit(as.character(x),\\.),[,2)) is simple and should work. No need for regular expressions here. -- Bert On Sat, Jul 7, 2012 at