Dear smart ones,
Image a vector 'test' that looks like so:
0
0.5
1.5
2.1
3.1
4
I'm looking for an efficient function that would do something like
moddown - function(test,integer){
for (element %in% test){
if (element%%integer != 0) {
return next lowest integer for which '%%'
tmp - c(0,.5,1.5,2.1,3.1,4)
floor(tmp/2)
[1] 0 0 0 1 1 2
floor(tmp/2)*2
[1] 0 0 0 2 2 4
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
Richard M. Heiberger wrote:
tmp - c(0,.5,1.5,2.1,3.1,4)
floor(tmp/2)
[1] 0 0 0 1 1 2
floor(tmp/2)*2
[1] 0 0 0 2 2 4
Thanks so much!
Joh
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the
I was a bit puzzed by:
formatC(6.65,format=f,digits=1)
[1] 6.6
So I experimented and found:
formatC(6.6501,format=f,digits=1)
[1] 6.6
formatC(6.651,format=f,digits=1)
[1] 6.7
round(6.6501,1)
[1] 6.7
round(6.651,1)
[1] 6.7
version
your number 6.6501 is to large to fit in a floating point
number. It takes 56 bits and there are only 54 in a real number so the
system see it as 6.65 and does the rounding to an even digit; 6.6
6.651 does fit into a real number (takes 54 bits) and this will
now round to
A good reference is:
*What Every Computer Scientist Should Know About Floating-Point*
*...*http://docs.sun.com/source/806-3568/ncg_goldberg.html
http://docs.sun.com/source/806-3568/ncg_goldberg.html
On 6/11/07, BXC (Bendix Carstensen) [EMAIL PROTECTED] wrote:
I was a bit puzzed by:
jim holtman wrote:
your number 6.6501 is to large to fit in a floating point
number. It takes 56 bits and there are only 54 in a real number so the
system see it as 6.65 and does the rounding to an even digit; 6.6
6.651 does fit into a real number (takes 54 bits) and
On Mon, 11 Jun 2007, jim holtman wrote:
your number 6.6501 is to large to fit in a floating point
number. It takes 56 bits and there are only 54 in a real number so the
system see it as 6.65 and does the rounding to an even digit; 6.6
I'll take it you mean a IEC60559 double,
The problem is most likely your use of cat() for output. Consider
x - 8665540.49905558
cat(x, \n)
8665540
cat(as.character(x), \n)
8665540.49905558
options(digits=10)
cat(x, \n)
8665540.499
So it would be best to do the conversions yourself, and I would
investigate using format() to do so.
Hello list,
I'm just getting started with using R - I have been trying over the past
day or so to work out a method for generating voronoi polygons for
PostGIS using SQL. I was able to put together a procedure which works
relatively well, but is somewhat inefficient. Someone on the PostGIS
list
Hi all,
I've got a matrix of fractional data that is all positive and greater than
zero that I would like to loosely classify, for lack of a better word. It
looks something like this :
1.07 1.11 1.27 1.59 0.97 0.76
2.23 0.98 0.71 0.88 1.19 1.02
What I'm looking for is a
Multiply by 4, round and divide by 4.
a - c(1.15,5.82)
round(a*4,digits=0)/4
-Original Message-
From: Ken Termiso [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 25, 2005 1:27 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Rounding fractional numbers to nearest fraction
Hi all,
I've got
PROTECTED]
To: Ken Termiso [EMAIL PROTECTED]
Subject: Re: [R] Rounding fractional numbers to nearest fraction
Date: Wed, 25 May 2005 14:30:44 -0400
x.1
[1] 1.07 1.11 1.27 1.59 0.97 0.76 2.23 0.98 0.71 0.88 1.19 1.02
as.integer(x.1*4)/4
[1] 1.00 1.00 1.25 1.50 0.75 0.75 2.00 0.75 0.50 0.75 1.00
as.integer(1.999)
is 1 intead of 2), which may not be what you want.
Andy
thx again,
ken
From: [EMAIL PROTECTED]
To: Ken Termiso [EMAIL PROTECTED]
Subject: Re: [R] Rounding fractional numbers to nearest fraction
Date: Wed, 25 May 2005 14:30:44 -0400
x.1
[1] 1.07 1.11 1.27
I would like to limit the significant figures of the calibrated
parameters determined by genoud() in the Rgenoud package. Below is some
example output, where column 1 is model run number, columns 2-7 are the
parameter values, and columns 8-12 are model fit statistics. I would
like genoud to
==
From: Waichler, Scott R [EMAIL PROTECTED]
Date: March 2, 2005 1:01:01 PM CST
To: r-help@stat.math.ethz.ch
Subject: [R] Rounding parameter values in genoud(), Rgenoud package
I would like to limit the significant figures of the calibrated
parameters
Thanks a lot, Marc, for this extra insight.
Note that Sun / Openoffice.org 's approxEqual(a,b)
is not even symmetric in a and b which I think is *really wrong*
((S's somewhat related all.equal.numeric() method *is* symmetric))
Marc == Marc Schwartz [EMAIL PROTECTED]
on 10 Jun 2003
On Wed, 2003-06-11 at 01:51, Martin Maechler wrote:
Thanks a lot, Marc, for this extra insight.
Note that Sun / Openoffice.org 's approxEqual(a,b)
is not even symmetric in a and b which I think is *really wrong*
((S's somewhat related all.equal.numeric() method *is* symmetric))
Glad to
Hi all,
I thought that I would follow up on this thread with some refined
information.
As I mentioned in a prior post in this thread, I posted a query to the
OOo folks regarding the inability to replicate the IEEE representation
issue in OOo Calc.
Recall the following results:
OOo Calc 1.0.2
was of interest since Excel is heavily used in that community.
-david paul
-Original Message-
From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 04, 2003 8:34 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Rounding problem R vs Excel
On 04 Jun 2003 00:24:08 -0500
I don't have the reference, but a biologist friend of mine
once showed me a refereed journal article that purported
to demonstrate numerical errors made by MSExcel. This
would have been Excel97 or Excel2000... In any case, the
journal's scope was biological in nature and the article
was of
On Wed, 2003-06-04 at 08:09, Paul, David A wrote:
I don't have the reference, but a biologist friend of mine
once showed me a refereed journal article that purported
to demonstrate numerical errors made by MSExcel. This
would have been Excel97 or Excel2000... In any case, the
journal's
David A. Paul wrote:
I don't have the reference, but a biologist friend of mine once
showed me a refereed journal article that purported to demonstrate
numerical errors made by MSExcel. This would have been Excel97 or
Excel2000... In any case, the journal's scope was biological in
nature
Hej,
just about excel -- excel 97 includ a kind of flying game (or what
ever it should be called). There was a landscape you could fly above,
and in the middle of it there were a screen with different names
(authors?). You had to put the cursor on a particular cell and click
a particular icon,
At 10:43 2003-06-04 -0300, you wrote:
David A. Paul wrote:
I don't have the reference, but a biologist friend of mine once
showed me a refereed journal article that purported to demonstrate
numerical errors made by MSExcel. This would have been Excel97 or
Excel2000... In any case, the
On Tue, 3 Jun 2003 09:49:44 +0100, you wrote in message
[EMAIL PROTECTED]:
Duncan
If the numbers are not represently exactly how does R resolve problems like
the one below? Is there something that needs to be set up in the R
environment like the number of significant figures?
x-4.145*100+0.5
x
On Tue, 2003-06-03 at 08:32, Duncan Murdoch wrote:
On Tue, 3 Jun 2003 09:49:44 +0100, you wrote in message
[EMAIL PROTECTED]:
Duncan
If the numbers are not represently exactly how does R resolve problems like
the one below? Is there something that needs to be set up in the R
environment
On 04 Jun 2003 00:24:08 -0500, you wrote:
Excel 2002 (XP):
Cell Formula Value
= 0.5 - 0.4 - 0.1 0.E+00
=(0.5 - 0.4 - 0.1)-2.7755575615628900E-17
...
What is interesting is the change in the displayed value in Excel when
the second formula is surrounded
Does this script do what you want?
cround - function(x,digits=0) {
a - ifelse(x0,.5,-.5)
if (digits==0) {
floor(x+a)
} else {
m - 10^digits
floor(x*m+a)/m
}
}
cround(1.4535,1)
[1] 1.5
cround(1.4535,2)
[1] 1.45
cround(1.4535,3)
[1] 1.454
cround(1.4535,4)
[1] 1.4535
-
On Mon, 2 Jun 2003 20:50:20 -0400, you wrote:
Does this script do what you want?
cround - function(x,digits=0) {
a - ifelse(x0,.5,-.5)
if (digits==0) {
floor(x+a)
} else {
m - 10^digits
floor(x*m+a)/m
}
}
No, the problem is that R uses binary formats, and some numbers
White
- Original Message -
From: Duncan Murdoch [EMAIL PROTECTED]
To: Hedderik van Rijn [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Tuesday, June 03, 2003 2:40 AM
Subject: Re: [R] Rounding problem R vs Excel
On Mon, 2 Jun 2003 20:50:20 -0400, you wrote:
Does this script do what you want
For numbers ending in 5 Excel always rounds up and I want to reproduce this in R
rather than use the round function.
I have tried:
x-as.integer(x*100+0.5)/100
and
x-floor(x*100+0.5)/100
However, some values of x cause problems e.g
x-floor(4.145*100+0.5)/100
4.14
I have tried breaking it
32 matches
Mail list logo