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

Re: [R] number of decimal

2010-01-29 Thread Ivan Calandra
Hi, Actually, I have two steps, the first would be to import a csv file (read.csv). There I would need to have the same number of decimals as there are on the original file. Then I would run some analyses and probably export the results, e.g. ANOVA table (write.csv). Here too I would like to h

Re: [R] number of decimal

2010-01-28 Thread David Winsemius
On Jan 28, 2010, at 12:08 PM, Marc Schwartz wrote: On Jan 28, 2010, at 10:04 AM, David Winsemius wrote: On Jan 28, 2010, at 10:55 AM, Marc Schwartz wrote: Ivan, The default behavior for print()ing objects to the console in an R session is via the use of the print.* methods. For real nu

Re: [R] number of decimal

2010-01-28 Thread Marc Schwartz
On Jan 28, 2010, at 10:04 AM, David Winsemius wrote: > > On Jan 28, 2010, at 10:55 AM, Marc Schwartz wrote: > >> Ivan, >> >> The default behavior for print()ing objects to the console in an R session >> is via the use of the print.* methods. For real numerics, print.default() is >> used and

Re: [R] number of decimal

2010-01-28 Thread Peter Ehlers
Ivan, Now I'm no longer sure of just what you want. Are you concerned about the *internal* handling of numbers by R or just about the *printing* of numbers? As Marc has pointed out, internally R will use the full precision that your input allows. Perhaps you're using the F-value from the output

Re: [R] number of decimal

2010-01-28 Thread Ivan Calandra
I guess the easiest solution for me would therefore be to set options(digits) to a high number, and then round down if I need to! Thanks you both for your input! Ivan Le 1/28/2010 17:02, Peter Ehlers a écrit : Looks like I didn't read your post carefully enough. If you want some sort of global

Re: [R] number of decimal

2010-01-28 Thread Peter Ehlers
Looks like I didn't read your post carefully enough. If you want some sort of global option to set the display of numbers from any operation performed by R then that's not likely to be possible without capturing all output and formatting it yourself. As the saying goes 'good luck with that'. Note

Re: [R] number of decimal

2010-01-28 Thread David Winsemius
On Jan 28, 2010, at 10:55 AM, Marc Schwartz wrote: Ivan, The default behavior for print()ing objects to the console in an R session is via the use of the print.* methods. For real numerics, print.default() is used and the format is based upon the number of significant digits, not the num

Re: [R] number of decimal

2010-01-28 Thread Ivan Calandra
First things first: thanks for your help! I see where the confusion is. With formatC and sprintf, I have to store the numbers I want to change into x. I would like a way without applying a function on specific numbers because I can shorten the numbers that way, but it won't give me more deci

Re: [R] number of decimal

2010-01-28 Thread Marc Schwartz
Ivan, The default behavior for print()ing objects to the console in an R session is via the use of the print.* methods. For real numerics, print.default() is used and the format is based upon the number of significant digits, not the number of decimal places. There is also an interaction with p

Re: [R] number of decimal

2010-01-28 Thread Peter Ehlers
Ivan Calandra wrote: It looks to me that it does more or less the same as format(). Maybe I didn't explain myself correctly then. I would like to set the number of decimal by default, for the whole R session, like I do with options(digits=6). Except that digits sets up the number of digits (i

Re: [R] number of decimal

2010-01-28 Thread Ivan Calandra
It looks to me that it does more or less the same as format(). Maybe I didn't explain myself correctly then. I would like to set the number of decimal by default, for the whole R session, like I do with options(digits=6). Except that digits sets up the number of digits (including what is befor

Re: [R] number of decimal

2010-01-28 Thread Peter Ehlers
?formatC ?sprintf Ivan Calandra wrote: Hi everybody, I'm trying to set the number of decimals (i.e. the number of digits after the "."). I looked into options but I can only set the total number of digits, with options(digits=6). But since I have different variables with different order of m

[R] number of decimal

2010-01-28 Thread Ivan Calandra
Hi everybody, I'm trying to set the number of decimals (i.e. the number of digits after the "."). I looked into options but I can only set the total number of digits, with options(digits=6). But since I have different variables with different order of magnitude, I would like that they're all