Re: [R] [External] R rounding problem?

2020-09-03 Thread array chip via R-help
Thanks Richard. Got it now... On Thursday, September 3, 2020, 10:12:36 PM PDT, Richard M. Heiberger wrote: FAQ 7.31 On Fri, Sep 4, 2020 at 12:47 AM array chip via R-help wrote: > > Hello, > > I made a mistake today on simple counting in R, that almost got me into > trouble. After trying m

Re: [R] [External] R rounding problem?

2020-09-03 Thread Richard M. Heiberger
FAQ 7.31 On Fri, Sep 4, 2020 at 12:47 AM array chip via R-help wrote: > > Hello, > > I made a mistake today on simple counting in R, that almost got me into > trouble. After trying multiple times, I finally figured out it's rounding > issue in R. > > For exmaple, when I just simply type: > > >

Re: [R] R rounding problem?

2020-09-03 Thread JRG via R-help
On 2020-09-04 00:46, array chip via R-help wrote: > Hello, > > I made a mistake today on simple counting in R, that almost got me into > trouble. After trying multiple times, I finally figured out it's rounding > issue in R. > > For exmaple, when I just simply type: > >> (6.9-6.3) > 0.6 > [1] TRU

[R] R rounding problem?

2020-09-03 Thread array chip via R-help
Hello, I made a mistake today on simple counting in R, that almost got me into trouble. After trying multiple times, I finally figured out it's rounding issue in R. For exmaple, when I just simply type: > (6.9-6.3) > 0.6 [1] TRUE 6.9-6.3 should be 0.6 exactly, but R thinks that it's greater t

Re: [R] rounding off problem.....

2019-03-08 Thread Kevin Thorpe
I'm no expert in R internals or floating point computation, however, two things come to mind. First, I suspect the exact value is stored. It is just the printing that looks rounded. That is likely because 0.001 completely dominates the rest. To print in full precision, you would need over 200 d

Re: [R] rounding off problem.....

2019-03-08 Thread Eric Berger
"Is there any way ..." Two quick answers: 1. using base R functions and data types the answer is 'no' - a double (i.e. numeric) contains about 15 significant digits. So 5.678e-100 is fine but 0.01 + 5.678e-100 will keep the .0100 as the significant digits and "drop" the digits 80

Re: [R] Rounding behavior

2018-10-09 Thread Ryan Derickson
I thought it might be a floating issue but didn't see the connection. Thanks everyone. On Tue, Oct 9, 2018, 2:00 PM Benoit Vaillant wrote: > Hello, > > On Tue, Oct 09, 2018 at 01:14:54PM -0400, Ryan Derickson wrote: > > Apologies if this is a simple misunderstanding. > > See for example: > > htt

Re: [R] Rounding behavior

2018-10-09 Thread Benoit Vaillant
Hello, On Tue, Oct 09, 2018 at 01:14:54PM -0400, Ryan Derickson wrote: > Apologies if this is a simple misunderstanding. See for example: https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f > round((.575*100),0) gives 57 > round(57.5,0) gives 58 >

Re: [R] Rounding behavior

2018-10-09 Thread Jeff Newmiller
Floating point numbers are approximations in base 2, so any fractions not representing such numbers may round off in unexpected directions. sprintf( "%22.20f", 0.5 ) sprintf( "%22.20f", 0.575 ) See R FAQ 7.31. On October 9, 2018 10:14:54 AM PDT, Ryan Derickson wrote: >Hello, > >Apologies if t

Re: [R] Rounding behavior

2018-10-09 Thread Richard M. Heiberger
FAQ 7.31 Open this file in your favorite text editor on your computer system.file("../../doc/FAQ") 57.5 comes out even in binary, and .575 does not. > print(.575*100, digits=17) [1] 57.493 ## The fraction is less than .5, hence it gets rounded down to 57 > print(57.5, digits=17) [1] 5

[R] Rounding behavior

2018-10-09 Thread Ryan Derickson
Hello, Apologies if this is a simple misunderstanding. round((.575*100),0) gives 57 round(57.5,0) gives 58 Why? Ryan Derickson University of Cincinnati On Tue, Oct 9, 2018, 10:08 AM PIKAL Petr wrote: > Hi > > You could use brute force approach. Just print out "file.names" and > estimate orde

Re: [R] Rounding of problem with sum command in R

2017-08-23 Thread Marc Girondot via R-help
Le 22/08/2017 à 16:26, niharika singhal a écrit : Hello I have a vector v=c(0.0886,0.1744455,0.1379778,0.1209769,0.1573065,0.1134463,0.2074027) when i do sum(v) or 0.0886+0.1744455+0.1379778+0.1209769+0.1573065+0.1134463+0.2074027 i am getting output as 1 But if i add them manually i get

Re: [R] Rounding of problem with sum command in R

2017-08-22 Thread John Kane via R-help
Try options(digits=12) sum(v) BTW I don't get the same value as you did when you calculated manually. On Tuesday, August 22, 2017, 10:39:26 AM EDT, Bert Gunter wrote: ... and following up on Spencer's answer, see the "digits" argument of ?options and ?print.default. Cheers, Bert Bert Gunter

Re: [R] Rounding of problem with sum command in R

2017-08-22 Thread Bert Gunter
... and following up on Spencer's answer, see the "digits" argument of ?options and ?print.default. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

Re: [R] Rounding of problem with sum command in R

2017-08-22 Thread Spencer Graves
On 2017-08-22 9:26 AM, niharika singhal wrote: Hello I have a vector v=c(0.0886,0.1744455,0.1379778,0.1209769,0.1573065,0.1134463,0.2074027) when i do sum(v) or 0.0886+0.1744455+0.1379778+0.1209769+0.1573065+0.1134463+0.2074027 i am getting output as 1 No:  That's only the display:

[R] Rounding of problem with sum command in R

2017-08-22 Thread niharika singhal
Hello I have a vector v=c(0.0886,0.1744455,0.1379778,0.1209769,0.1573065,0.1134463,0.2074027) when i do sum(v) or 0.0886+0.1744455+0.1379778+0.1209769+0.1573065+0.1134463+0.2074027 i am getting output as 1 But if i add them manually i get 1.0026 I do not want to round of my value since

Re: [R] rounding down with as.integer

2015-01-02 Thread Mike Miller
On Fri, 2 Jan 2015, Duncan Murdoch wrote: On 01/01/2015 10:05 PM, Mike Miller wrote: This is how big those errors are: 512*.Machine$double.eps [1] 1.136868e-13 Under other conditions you also were seeing errors of twice that, or 1024*.Machine$double.eps. It might not be a coincidence th

Re: [R] rounding down with as.integer

2015-01-02 Thread peter dalgaard
On 02 Jan 2015, at 04:05 , Mike Miller wrote: > > ...but why are we seeing errors so much bigger than the machine precision? > Why does it change at 2? Because relative errors in the one-thousands part are roughly a thousand times bigger than errors in the number itself? Put differently: th

Re: [R] rounding down with as.integer

2015-01-02 Thread Duncan Murdoch
On 01/01/2015 10:05 PM, Mike Miller wrote: > On Thu, 1 Jan 2015, Duncan Murdoch wrote: > >> On 01/01/2015 1:21 PM, Mike Miller wrote: >> >>> I understand that it's all about the problem of representing digital >>> numbers in binary, but I still find some of the results a little >>> surprising, l

Re: [R] rounding down with as.integer

2015-01-01 Thread Mike Miller
On Thu, 1 Jan 2015, Duncan Murdoch wrote: On 01/01/2015 1:21 PM, Mike Miller wrote: I understand that it's all about the problem of representing digital numbers in binary, but I still find some of the results a little surprising, like that list of numbers from the table() output. For anothe

Re: [R] rounding down with as.integer

2015-01-01 Thread Mike Miller
Yes, Ted, that also works, but it's very slow: # read in values: data <- scan( file=RECIP_IN, what=double(), nmax=recip_N*16000) Read 48013406 items # convert to integer by adding .5 and rounding down: ptm <- proc.time() ; ints <- as.integer( 1000 * data + .5 ) ; proc.time()-ptm user sys

Re: [R] rounding down with as.integer

2015-01-01 Thread Mike Miller
On Thu, 1 Jan 2015, Duncan Murdoch wrote: On 01/01/2015 1:21 PM, Mike Miller wrote: On Thu, 1 Jan 2015, Duncan Murdoch wrote: On 31/12/2014 8:44 PM, David Winsemius wrote: On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: This is probably a FAQ, and I don't really have a question about it,

Re: [R] rounding down with as.integer

2015-01-01 Thread Ted Harding
I've been followeing this little tour round the murkier bistros in the back-streets of R with interest! Then it occurred to me: What is wrong with [using example data]: x0 <- c(0,1,2,0.325,1.12,1.9,1.003) x1 <- as.integer(as.character(1000*x0)) n1 <- c(0,1000,2000,325,1120,1900,1003) x1 -

Re: [R] rounding down with as.integer

2015-01-01 Thread Duncan Murdoch
On 01/01/2015 2:43 PM, Mike Miller wrote: > On Thu, 1 Jan 2015, Duncan Murdoch wrote: > >> On 01/01/2015 1:21 PM, Mike Miller wrote: >>> On Thu, 1 Jan 2015, Duncan Murdoch wrote: >>> On 31/12/2014 8:44 PM, David Winsemius wrote: > > On Dec 31, 2014, at 3:24 PM, Mike Miller wrote:

Re: [R] rounding down with as.integer

2015-01-01 Thread Mike Miller
I'd have to say thanks, but no thanks, to that one! ;-) The problem is that it will take a long time and it will give the same answer. The first time I did this kind of thing, a year or two ago, I manipulated the text data to produce integers before putting the data into R. The data were a

Re: [R] rounding down with as.integer

2015-01-01 Thread Richard M. Heiberger
Interesting. Following someone on this list today the goal is input the data correctly. My inclination would be to read the file as text, pad each number to the right, drop the decimal point, and then read it as an integer. 0 1 2 0.325 1.12 1.9 0.000 1.000 2.000 0.325 1.120 1.900 1000 2000 03

Re: [R] rounding down with as.integer

2015-01-01 Thread Duncan Murdoch
On 01/01/2015 1:21 PM, Mike Miller wrote: > On Thu, 1 Jan 2015, Duncan Murdoch wrote: > >> On 31/12/2014 8:44 PM, David Winsemius wrote: >>> >>> On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: >>> This is probably a FAQ, and I don't really have a question about it, but I just ran across

Re: [R] rounding down with as.integer

2015-01-01 Thread Mike Miller
On Thu, 1 Jan 2015, Duncan Murdoch wrote: On 31/12/2014 8:44 PM, David Winsemius wrote: On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: This is probably a FAQ, and I don't really have a question about it, but I just ran across this in something I was working on: as.integer(1000*1.003) [1

Re: [R] rounding down with as.integer

2015-01-01 Thread Duncan Murdoch
On 31/12/2014 8:44 PM, David Winsemius wrote: > > On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: > >> This is probably a FAQ, and I don't really have a question about it, but I >> just ran across this in something I was working on: >> >>> as.integer(1000*1.003) >> [1] 1002 >> >> I didn't expect

Re: [R] rounding down with as.integer

2014-12-31 Thread David Winsemius
Read the message at the bottom of every message from rhelp. -- David. On Dec 31, 2014, at 8:09 PM, Zaid Bhatti wrote: > How can I unsubscribe to not receive loop e mails? > > Sent from my Huawei Mobile > > David Winsemius wrote: > > > On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: > >> T

Re: [R] rounding down with as.integer

2014-12-31 Thread Zaid Bhatti
How can I unsubscribe to not receive loop e mails? Sent from my Huawei Mobile David Winsemius wrote: On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: > This is probably a FAQ, and I don't really have a question about it, but I > just ran across this in something I was working on: > >> as.inte

Re: [R] rounding down with as.integer

2014-12-31 Thread David Winsemius
On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: > This is probably a FAQ, and I don't really have a question about it, but I > just ran across this in something I was working on: > >> as.integer(1000*1.003) > [1] 1002 > > I didn't expect it, but maybe I should have. I guess it's about the mac

[R] rounding down with as.integer

2014-12-31 Thread Mike Miller
This is probably a FAQ, and I don't really have a question about it, but I just ran across this in something I was working on: as.integer(1000*1.003) [1] 1002 I didn't expect it, but maybe I should have. I guess it's about the machine precision added to the fact that as.integer always round

Re: [R] rounding to whole number

2014-03-20 Thread Boris Steipe
Try ?ceiling > ceiling(0.4) [1] 1 B. On 2014-03-20, at 3:42 PM, Kristi Glover wrote: > Hi R User, > I was trying to convert a decimal value into integral (whole number). I used > round function but some of the cells have the value less than 0.5 and it > converted into 0. But I wanted th

Re: [R] rounding to whole number

2014-03-20 Thread Ted Harding
On 20-Mar-2014 19:42:35 Kristi Glover wrote: > Hi R User, > I was trying to convert a decimal value into integral (whole number). I used > round function but some of the cells have the value less than 0.5 and it > converted into 0. But I wanted these cell to have 1 instead of 0. Another > way, I c

Re: [R] rounding to whole number

2014-03-20 Thread Sarah Goslee
What about: > ceiling(data[,2:3]) A B 1 0 1 2 3 1 3 3 3 4 2 3 Note that ceiling is referenced in ?round Thanks for the clear reproducible example. Sarah On Thu, Mar 20, 2014 at 3:42 PM, Kristi Glover wrote: > Hi R User, > I was trying to convert a decimal value into integral (whole number)

[R] rounding to whole number

2014-03-20 Thread Kristi Glover
Hi R User, I was trying to convert a decimal value into integral (whole number). I used round function but some of the cells have the value less than 0.5 and it converted into 0. But I wanted these cell to have 1 instead of 0. Another way, I could multiply by 10. But l did not want it because i

Re: [R] Rounding

2013-01-06 Thread Artur Augusto
For more details about floating-point: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html 2013/1/5 peter dalgaard > > On Jan 5, 2013, at 20:30 , Rolf Turner wrote: > > > On 01/06/2013 07:42 AM, David Arnold wrote: > >> Hi, > >> > >> Can someone explain this: > >> > >>> options(digit

Re: [R] Rounding

2013-01-05 Thread peter dalgaard
On Jan 5, 2013, at 20:30 , Rolf Turner wrote: > On 01/06/2013 07:42 AM, David Arnold wrote: >> Hi, >> >> Can someone explain this: >> >>> options(digits=20) >>> 1/3 >> [1] 0.1483 >> >> Why the 1483 at the end? > > There are 10 sorts of people; those who understand binary > ari

Re: [R] Rounding

2013-01-05 Thread Rolf Turner
On 01/06/2013 07:42 AM, David Arnold wrote: > Hi, > > Can someone explain this: > >> options(digits=20) >> 1/3 > [1] 0.1483 > > Why the 1483 at the end? There are 10 sorts of people; those who understand binary arithmetic and those who don't. See also FAQ 7.31. cheers, Rolf

Re: [R] Rounding

2013-01-05 Thread R. Michael Weylandt
On Sat, Jan 5, 2013 at 6:48 PM, R. Michael Weylandt wrote: > To be curt, "it's complicated," but it basically comes down to the > fact that 1/3 is not expressible by a finite sequence of powers of 2 > so it can't be perfectly represented in binary. But of course, that in turn leads to gems like t

Re: [R] Rounding

2013-01-05 Thread Achim Zeileis
On Sat, 5 Jan 2013, David Arnold wrote: Hi, Can someone explain this: options(digits=20) 1/3 [1] 0.1483 Why the 1483 at the end? Due to floating-point arithmetic, see FAQ 7.31. Thanks, David. david-arnolds-macbook-pro-2:~ darnold$ R --version R version 2.15.2 (2012-10-

Re: [R] Rounding

2013-01-05 Thread R. Michael Weylandt
On Sat, Jan 5, 2013 at 6:42 PM, David Arnold wrote: > Hi, > > Can someone explain this: > >> options(digits=20) >> 1/3 > [1] 0.1483 > > Why the 1483 at the end? To be curt, "it's complicated," but it basically comes down to the fact that 1/3 is not expressible by a finite sequence

[R] Rounding

2013-01-05 Thread David Arnold
Hi, Can someone explain this: > options(digits=20) > 1/3 [1] 0.1483 Why the 1483 at the end? Thanks, David. david-arnolds-macbook-pro-2:~ darnold$ R --version R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3

Re: [R] rounding of integer

2012-02-05 Thread Jorge I Velez
Try round(1003, digits = -3) HTH, Jorge.- On Mon, Feb 6, 2012 at 1:40 AM, arunkumar <> wrote: > Hi > > I need to round integer > \ > eg if my value is 1003 > > i want to make it 1000 > > Thanks in advance > > > > - > Thanks in Advance >Arun > -- > View this message in context:

Re: [R] rounding of integer

2012-02-05 Thread David Winsemius
On Feb 6, 2012, at 1:40 AM, arunkumar wrote: Hi I need to round integer \ eg if my value is 1003 i want to make it 1000 ?round -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/li

[R] rounding of integer

2012-02-05 Thread arunkumar1111
Hi I need to round integer \ eg if my value is 1003 i want to make it 1000 Thanks in advance - Thanks in Advance Arun -- View this message in context: http://r.789695.n4.nabble.com/rounding-of-integer-tp4360549p4360549.html Sent from the R help mailing list archive at Nabble.co

Re: [R] "rounding" to a number that is LOWER than my number

2011-09-16 Thread Dimitri Liakhovitski
Thanks a lot, guys - very helpful! On Fri, Sep 16, 2011 at 12:52 PM, Bert Gunter wrote: > This is easy to do (e.g. divide by the appropriate power of 10, use floor, > multiply the power of 10), but you are going about it in the wrong way. > > See the "xaxs"  component of the ?par  argument list f

Re: [R] "rounding" to a number that is LOWER than my number

2011-09-16 Thread Bert Gunter
This is easy to do (e.g. divide by the appropriate power of 10, use floor, multiply the power of 10), but you are going about it in the wrong way. See the "xaxs" component of the ?par argument list for the right way. -- Bert On Fri, Sep 16, 2011 at 9:28 AM, Dimitri Liakhovitski < dimitri.liakh

Re: [R] "rounding" to a number that is LOWER than my number

2011-09-16 Thread Sarah Goslee
Just for fun: roundDown <- function(x, digits = 2) { currplaces <- nchar(as.character((floor(x x <- x * 10 ^ (digits - currplaces) x <- floor(x) x <- x / (10 ^ (digits - currplaces)) x } > roundDown(1.98, 2) [1] 1.9 > roundDown(1.98, 1) [1] 1 > roundDown(1.98, 3) [1] 1.98 > > > roundDown(2

Re: [R] "rounding" to a number that is LOWER than my number

2011-09-16 Thread Dimitri Liakhovitski
In other words, I am looking for something like floor, but more flexible - as it should allow me to: turn 1.98 into 1.9 or turn 298 into 290, etc. Dimitri On Fri, Sep 16, 2011 at 12:28 PM, Dimitri Liakhovitski wrote: > Hello! > > What function would allow me to "round" down, rather than up? > For

[R] "rounding" to a number that is LOWER than my number

2011-09-16 Thread Dimitri Liakhovitski
Hello! What function would allow me to "round" down, rather than up? For example, x<-1.98 I'd like to get 1.9 - rather than 2.0. Reason - I am creating a minimum for an axis for a plot, and I need it to be lower than x (which, in turn, is the lowest number already). Thank you! -- Dimitri Liakho

Re: [R] Rounding variables in a data frame

2011-01-15 Thread Joshua Wiley
On Fri, Jan 14, 2011 at 11:16 PM, Phil Spector wrote: > Is sapply really necessary here? Apparently not, and it is certainly more cumbersome. Because data frames can contain a mix of classes, I thought that round() did not have a method for them (in retrospect that does not make much sense). I h

Re: [R] Rounding variables in a data frame

2011-01-15 Thread Pete B
Bill, Joshua, Phil Thanks for the suggestions. Very much appreciated. Kind regards Pete -- View this message in context: http://r.789695.n4.nabble.com/Rounding-variables-in-a-data-frame-tp3218729p3219060.html Sent from the R help mailing list archive at Nabble.com. _

Re: [R] Rounding variables in a data frame

2011-01-14 Thread Phil Spector
Is sapply really necessary here? exc = !names(d) %in% "d3" d[,exc] = round(d[,exc]) d d1 d2 d3 d4 1 10 6 2.3749642 -4 2 11 6 -0.2081097 -2 3 10 4 1.2675955 -4 4 10 8 1.2468859 -2 5 10 6 2.7193027 -4 6 9 6 1.9195531 -5 7 9 6 2.8188036 -6 8 10 7 2.5755148 -4 9

Re: [R] Rounding variables in a data frame

2011-01-14 Thread Joshua Wiley
Hi Pete, Here is one option. The first part of sapply() just serves to get all names of d except those you excluded in 'exc'. If you were including fewer variables than you were excluding, just get rid of the logical ! operator. d <- data.frame(d1 = rnorm(10, 10), d2 = rnorm(10, 6), d3 = rnor

Re: [R] Rounding variables in a data frame

2011-01-14 Thread Bill.Venables
__ From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Pete B [peter.breckn...@bp.com] Sent: 15 January 2011 14:53 To: r-help@r-project.org Subject: [R] Rounding variables in a data frame Hi All I am trying to use the round function on some columns of a dataframe while leavi

[R] Rounding variables in a data frame

2011-01-14 Thread Pete B
Hi All I am trying to use the round function on some columns of a dataframe while leaving others unchanged. I wish to specify those columns to leave unchanged. My attempt is below - here, I would like the column d3 to be left but columns d1, d2 and d4 to be rounded to 0 decimal places. I would w

Re: [R] rounding up (always)

2010-10-20 Thread jim holtman
why don't you just use 'pretty' > pretty(c(-1225, 2224)) [1] -1500 -1000 -500 0 500 1000 1500 2000 2500 > pretty(c(-4.28, 6.45)) [1] -6 -4 -2 0 2 4 6 8 > On Wed, Oct 20, 2010 at 8:38 PM, Dimitri Liakhovitski wrote: > Thank you for your help, everyone. > Actually, I am building a

Re: [R] rounding up (always)

2010-10-20 Thread Dimitri Liakhovitski
Thanks a lot, David - I'll try this solution. Dimitri On Wed, Oct 20, 2010 at 9:54 PM, David Winsemius wrote: > > On Oct 20, 2010, at 8:38 PM, Dimitri Liakhovitski wrote: > >> Thank you for your help, everyone. >> Actually, I am building a lot of graphs (in a loop) but the values on >> the y axes

Re: [R] rounding up (always)

2010-10-20 Thread David Winsemius
On Oct 20, 2010, at 8:38 PM, Dimitri Liakhovitski wrote: Thank you for your help, everyone. Actually, I am building a lot of graphs (in a loop) but the values on the y axes from graph to graph could range from [-5; 5] to [-10,000; 10,000]. So, I am trying to create ylim ranging from ymin to yma

Re: [R] rounding up (always)

2010-10-20 Thread Dimitri Liakhovitski
Thank you for your help, everyone. Actually, I am building a lot of graphs (in a loop) but the values on the y axes from graph to graph could range from [-5; 5] to [-10,000; 10,000]. So, I am trying to create ylim ranging from ymin to ymax such that they look appropriate for the range. For example,

Re: [R] rounding up (always)

2010-10-20 Thread Ted Harding
On 20-Oct-10 21:27:46, Duncan Murdoch wrote: > On 20/10/2010 5:16 PM, Dimitri Liakhovitski wrote: >> Hello! >> >> I am trying to round the number always up - i.e., whatever the >> positive number is, I would like it to round it to the closest 10 that >> is higher than this number, the closest 100 t

Re: [R] rounding up (always)

2010-10-20 Thread Clint Bowman
x<-runif(10,1,10) # generate 10 numbers as.integer(log(x,10)+1) -- Clint BowmanINTERNET: cl...@ecy.wa.gov Air Quality Modeler INTERNET: cl...@math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600

Re: [R] rounding up (always)

2010-10-20 Thread Duncan Murdoch
On 20/10/2010 5:16 PM, Dimitri Liakhovitski wrote: Hello! I am trying to round the number always up - i.e., whatever the positive number is, I would like it to round it to the closest 10 that is higher than this number, the closest 100 that is higher than this number, etc. For example: x<-3241.

[R] rounding up (always)

2010-10-20 Thread Dimitri Liakhovitski
Hello! I am trying to round the number always up - i.e., whatever the positive number is, I would like it to round it to the closest 10 that is higher than this number, the closest 100 that is higher than this number, etc. For example: x<-3241.388 signif(x,1) rounds to the closest thousand, i.e.

Re: [R] rounding issues

2010-10-14 Thread Ted Harding
On 14-Oct-10 09:43:53, Federico Calboli wrote: > Hi All, > > I'm running the now almost-to-be upgraded R 2.11.1 on a Intel Mac, and > on a Ubuntu machine, but the problem I see is the same. I noticed the > following behaviour: > > 407585.91 * 0.8 > [1] 326068.7 -- the right asnwer is 326068.728

[R] rounding issues

2010-10-14 Thread Federico Calboli
Hi All, I'm running the now almost-to-be upgraded R 2.11.1 on a Intel Mac, and on a Ubuntu machine, but the problem I see is the same. I noticed the following behaviour: 407585.91 * 0.8 [1] 326068.7 -- the right asnwer is 326068.728 round(407585.91 * 0.8, 2) [1] 326068.7 -- same issue 407585.

Re: [R] Rounding Elements of a Matrix

2010-09-20 Thread Raphael Fraser
a MD > > Work: 301-451-8575 > Mobile: 301-204-5642 > Email: zoppo...@mail.nih.gov > > From: Raphael Fraser [raphael.fra...@gmail.com] > Sent: Monday, September 20, 2010 12:21 PM > To: r-help@r-project.org > Subject: [R] Rounding

Re: [R] Rounding Elements of a Matrix

2010-09-20 Thread David Winsemius
On Sep 20, 2010, at 12:25 PM, Joshua Wiley wrote: Hi Raphael, mat <- matrix(rnorm(100), ncol = 2) round(mat, 2) for documentation see ?round Thanks, Josh. I was having trouble a couple of minutes ago remembering this. Getting old, I guess. In constructing my thanks to Josh I tested: pr

Re: [R] Rounding Elements of a Matrix

2010-09-20 Thread Joshua Wiley
Hi Raphael, mat <- matrix(rnorm(100), ncol = 2) round(mat, 2) for documentation see ?round Cheers, Josh On Mon, Sep 20, 2010 at 9:21 AM, Raphael Fraser wrote: > I have a 2x50 matrix and would like to round all the elements to 2 > decimal places. Can any one help? > > Thanks, > Raphael > > ___

[R] Rounding Elements of a Matrix

2010-09-20 Thread Raphael Fraser
I have a 2x50 matrix and would like to round all the elements to 2 decimal places. Can any one help? Thanks, Raphael __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.

Re: [R] rounding up to nearest integer

2010-05-25 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Mohan L > Sent: Monday, May 24, 2010 6:26 PM > To: r-help@r-project.org > Subject: [R] rounding up to nearest integer > > Dear All, > > I hav

Re: [R] rounding up to nearest integer

2010-05-24 Thread Nikhil Kaza
?round On May 24, 2010, at 9:26 PM, Mohan L wrote: Dear All, I have a data frame "data" and the below is the str of "data" : $ Feb : int 1 1195 0 11 28 152 24 2 1 1470 ... $ Mar : int 0 1212 0 17 27 184 15 1 1 1311 ... $ Apr : int 2 1244 1 15 23 135 11 0 1 991 ... $ May : int 2

[R] rounding up to nearest integer

2010-05-24 Thread Mohan L
Dear All, I have a data frame "data" and the below is the str of "data" : $ Feb : int 1 1195 0 11 28 152 24 2 1 1470 ... $ Mar : int 0 1212 0 17 27 184 15 1 1 1311 ... $ Apr : int 2 1244 1 15 23 135 11 0 1 991 ... $ May : int 2 1158 2 10 23 111 16 1 1 1237 ... $ Jun : int 0 84

Re: [R] Rounding like in finances

2010-02-22 Thread Oliver
Duncan Murdoch stats.uwo.ca> writes: [...] > MASS (function rational()) > rcdd > Rmpfr [...] OK, I will look for those packages. Maybe they will help. Thank you. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEA

Re: [R] Rounding like in finances

2010-02-22 Thread Duncan Murdoch
On 22/02/2010 9:57 AM, Oliver wrote: Hello, which packages are you talking about? And... are thoise packages using integer-based calculations? I don't use this, but the ones I'd look in would be: MASS (function rational()) rcdd Rmpfr You can use RSiteSearch("rational") to look for more.

Re: [R] Rounding like in finances

2010-02-22 Thread Oliver
Hello, which packages are you talking about? And... are thoise packages using integer-based calculations? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posti

Re: [R] Rounding like in finances

2010-02-22 Thread Ivan Calandra
same result with R2.10.1 on Windows... Le 2/22/2010 15:34, Oliver a écrit : Oh strange... round(108.275 , 2) [1] 108.28 round(208.275 , 2) [1] 208.28 round(308.275 , 2) [1] 308.27 looks not like what one should expect... R version 2.9.2 (2009-0

Re: [R] Rounding like in finances

2010-02-22 Thread Duncan Murdoch
On 22/02/2010 9:06 AM, Oliver wrote: Hello, I need to have a "kaufmaennisches Runden" function. Is there already something like that? It means: rounding up the 5, instead of rounding it down. So, 245.455 would give 245.46 I found no option for this. Maybe there is a package for it? This is

Re: [R] Rounding like in finances

2010-02-22 Thread Oliver
Oh strange... > round(108.275 , 2) [1] 108.28 > round(208.275 , 2) [1] 208.28 > round(308.275 , 2) [1] 308.27 > looks not like what one should expect... R version 2.9.2 (2009-08-24) Ciao, Oliver __ R-help@r-project.org mailing list https://s

Re: [R] Rounding like in finances

2010-02-22 Thread Henrique Dallazuanna
round(245.455, 2) ? On Mon, Feb 22, 2010 at 11:06 AM, Oliver wrote: > Hello, > > I need to have a "kaufmaennisches Runden" function. > > Is there already something like that? > > It means: rounding up the 5, instead of rounding it down. > > So, 245.455 would give 245.46 > > I found no option for

[R] Rounding like in finances

2010-02-22 Thread Oliver
Hello, I need to have a "kaufmaennisches Runden" function. Is there already something like that? It means: rounding up the 5, instead of rounding it down. So, 245.455 would give 245.46 I found no option for this. Maybe there is a package for it? Oliver __

Re: [R] Rounding a Measurement to be Consistent with its Uncertainty

2009-12-05 Thread Tom La Bone
Uwe Ligges-3 wrote: > > > > Tom La Bone wrote: >> I have a measurement of 8165.666 and an uncertainty of 338.9741 (the >> units of >> both are unimportant). I can easily round the uncertainty to two >> significant >> digits with signif(338.9741,2), which gives 340. Is there a function in R >>

Re: [R] Rounding a Measurement to be Consistent with its Uncertainty

2009-12-05 Thread Uwe Ligges
Tom La Bone wrote: I have a measurement of 8165.666 and an uncertainty of 338.9741 (the units of both are unimportant). I can easily round the uncertainty to two significant digits with signif(338.9741,2), which gives 340. Is there a function in R that will take 8165.666 and round it to be cons

[R] Rounding a Measurement to be Consistent with its Uncertainty

2009-12-03 Thread Tom La Bone
I have a measurement of 8165.666 and an uncertainty of 338.9741 (the units of both are unimportant). I can easily round the uncertainty to two significant digits with signif(338.9741,2), which gives 340. Is there a function in R that will take 8165.666 and round it to be consistent with its uncert

Re: [R] Rounding and printing

2009-10-29 Thread David Winsemius
On Oct 29, 2009, at 12:29 PM, Alan Cohen wrote: Hello, I am trying to print a table with numbers all rounded to the same number of digits (one after the decimal), but R seems to want to not print ".0" for integers. I can go in and fix it one number at a time, but I'd like to understand

Re: [R] Rounding and printing

2009-10-29 Thread Karl Ove Hufthammer
On Thu, 29 Oct 2009 12:29:42 -0400 Alan Cohen wrote: > I am trying to print a table with numbers all rounded to the same > number of digits (one after the decimal), but R seems to want to not > print ".0" for integers. 'round' only rounds numbers; it doesn't format them. Use 'formatC' instead

[R] Rounding and printing

2009-10-29 Thread Alan Cohen
Hello, I am trying to print a table with numbers all rounded to the same number of digits (one after the decimal), but R seems to want to not print ".0" for integers. I can go in and fix it one number at a time, but I'd like to understand the principle. Here's an example of the code. The pro

[R] Rounding error in seq(...)

2009-10-25 Thread David Airey
>> can you explain that a little more detailed? >> Perhaps I miss the background knowledge - but it seems just absurd to me. >> >> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? >> >> why is >> x <- 0.1 + 0.1 +0.1 >> not equal to >> y <- 0.3 > > Remember that this is in BINARY a

Re: [R] Rounding error in seq(...)

2009-09-30 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: Peter Dalgaard [mailto:p.dalga...@biostat.ku.dk] > Sent: Wednesday, September 30, 2009 3:58 PM > To: Nordlund, Dan (DSHS/RDA) > Cc: Douglas Bates; r help > Subject: Re: [R] Rounding error in seq(...) > <<>> > > > &g

Re: [R] Rounding error in seq(...)

2009-09-30 Thread Peter Dalgaard
Nordlund, Dan (DSHS/RDA) wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Douglas Bates Sent: Wednesday, September 30, 2009 3:06 PM To: Peter Dalgaard Cc: r help; Duncan Murdoch Subject: Re: [R] Rounding error in seq(...) On

Re: [R] Rounding error in seq(...)

2009-09-30 Thread Erik Iverson
> In an earlier thread on this theme I believe that someone quoted Brian > Kernighan as saying "10 times 0.1 is hardly ever 1" but I haven't been > able to track down the quote. Can anyone point us to such a quote? > It summarizes the situation succinctly, See FAQ 7.31 :) ___

Re: [R] Rounding error in seq(...)

2009-09-30 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Douglas Bates > Sent: Wednesday, September 30, 2009 3:06 PM > To: Peter Dalgaard > Cc: r help; Duncan Murdoch > Subject: Re: [R] Rounding error in seq(...

Re: [R] Rounding error in seq(...)

2009-09-30 Thread David Winsemius
On Sep 30, 2009, at 6:05 PM, Douglas Bates wrote: On Wed, Sep 30, 2009 at 2:32 PM, Peter Dalgaard> wrote: Martin Batholdy wrote: hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no ro

Re: [R] Rounding error in seq(...)

2009-09-30 Thread Douglas Bates
On Wed, Sep 30, 2009 at 2:32 PM, Peter Dalgaard wrote: > Martin Batholdy wrote: >> >> hum, >> >> can you explain that a little more detailed? >> Perhaps I miss the background knowledge - but it seems just absurd to me. >> >> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? >> >> why is

Re: [R] Rounding error in seq(...)

2009-09-30 Thread Ted Harding
On 30-Sep-09 19:32:46, Peter Dalgaard wrote: > Martin Batholdy wrote: >> hum, >> >> can you explain that a little more detailed? >> Perhaps I miss the background knowledge - but it seems just absurd to >> me. >> >> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? >> >> why is >> x <

Re: [R] Rounding error in seq(...)

2009-09-30 Thread Duncan Murdoch
On 9/30/2009 3:59 PM, Ista Zahn wrote: For my own edification more than anything (I never took computer science): is a = seq(0.1,0.9,by=0.1) a <- as.character(a) a[3] == "0.3" [1] TRUE safe? No. Someone might be in a locale where the comma is used as the decimal separator. Take a look at

Re: [R] Rounding error in seq(...)

2009-09-30 Thread Ista Zahn
For my own edification more than anything (I never took computer science): is > a = seq(0.1,0.9,by=0.1) > a <- as.character(a) > a[3] == "0.3" [1] TRUE safe? -Ista On Wed, Sep 30, 2009 at 3:46 PM, cls59 wrote: > > > Martin Batholdy wrote: >> >> hum, >> >> can you explain that a little more det

Re: [R] Rounding error in seq(...)

2009-09-30 Thread cls59
Martin Batholdy wrote: > > hum, > > can you explain that a little more detailed? > Perhaps I miss the background knowledge - but it seems just absurd to > me. > > 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? > > Unfortunately this comes as an utter shock to many people wh

  1   2   >