Re: [R] Number of decimal places

2012-10-26 Thread Rui Barradas
Hello, There might be another problem with some of the numbers in the example. R uses C's double numeric type and that means that the limit is around 16 decimal digits of precision. One of the numbers has 23, so there will allways be loss of accuracy. a <- 234235423.56 b <-

Re: [R] Number of decimal places

2012-10-26 Thread David Winsemius
Putting back the context: ( We are not looking at this with Nabble.) > When estimating values ​​each determined similarly, and in which get to them > by algebraic operations in some cases, are rounded with 0 decimal places and > in other cases with 2 or 3 decimal places. What is happening? > Than

Re: [R] Number of decimal places

2012-10-26 Thread DMMS
For example > a=12344.567 > a [1] 12344.57 > b=234.567 > b [1] 234.567 > a=234235423.56 > a [1] 1.11e+20 > b=111.898 > b [1] 112 > -- View this message in context: http://r.789695.n4.nabble.com/Number-of-decimal-places-tp4647549p4647552.html Sent from the R he

[R] Number of decimal places

2012-10-26 Thread DMMS
When estimating values ​​each determined similarly, and in which get to them by algebraic operations in some cases, are rounded with 0 decimal places and in other cases with 2 or 3 decimal places. What is happening? Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Numbe

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

2012-07-10 Thread Martin Ivanov
nteger multiple 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] nu

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 > ..^ > Rpi->3.1415926535897931159

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

2012-07-09 Thread Jim Plante
pi,digits=36) > b > [1] "3.14159265358979311599796346854418516" > > identical(a,b) > [1] TRUE > > > identical(a,signif(pi,digits=35)) > [1] FALSE > > > A.K. > > > > - Original Message - > From: Petr Savicky > To: r-help@

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 n

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

2012-07-08 Thread arun
ent: 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 thought of also (as well as my numerical routing) suggesting > a "gsub()" type solution like Joshua's below, but held ba

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 funct

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

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 computatio

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

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

2012-07-07 Thread arun
56237309514547462185873882845" #using >22 x <- c("3.14", "3.142", "3.1400", "123456.123456789", "123456789.123456789",formatC(pi,format="f",digits=35),formatC(sqrt(2),format="f",digits=50))  decimalnumcount(x) #[1]

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 determin

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 bina

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)) nchar(gsub("(.*\\.)|([0]

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 > availabl

[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