Re: [R] Is there in R a function equivalent to the mround, as found in most spreadsheets?

2008-05-11 Thread Alberto Santini

Hello Luca.


Dr. Ottorino-Luca Pantani wrote:
 
 ...
 
 c(1803.02, 193.51, 3.47)
 
 Each solution is to be taken with 3 different pipettes (5000, 250 and 10 
 µL Volume max) and each of those delivers volumes in steps of 50 µL,  5 
 µL  or 1µL, respectively
 Since the above values  would eventually become
 
 c(1800, 195, 3)
 
 ...
 

You find a complete solution at 
  http://albertosantini.blogspot.com/2008/05/mround.html

It checks the sign of the number and the multiple and it hacks the issue of
rounding off a 5 respect IEC 60559 standard.

The test cases are:

mround(10, 3) # 9
mround(-10, -3) # -9
mround(1.3, 0.2) # 1.4
mround(5, -2) # error
mround(1.7, 0.2) # 1.8
mround(321.123, 0.12) # 321.12
mround(1803.02, 50) # 1800
mround(193.51, 5) # 195
mround(3.47, 1) # 3


Regards,
Alberto


-- 
View this message in context: 
http://www.nabble.com/Is-there-in-R-a-function-equivalent-to-the-mround%2C-as-found-in-most-spreadsheets--tp17143519p17170296.html
Sent from the R help mailing list archive at Nabble.com.

__
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/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Is there in R a function equivalent to the mround, as found in most spreadsheets?

2008-05-09 Thread Dr. Ottorino-Luca Pantani

Dear R-users,

I have the following problem

In a lab experiment I have to mix three solutions to get different 
concentrations of various molecules in a cuvette


I've used R to calculate the necessary µliters for each of the level of 
the experiment and I must confess that it is more useful and easier to 
achieve the results than using spreadsheets.


But there's a problem.

Imagine that for a particular cuvette (I have 112 different cuvettes !!) 
you have to mix the following volumes of solution A, B, and C respectively.


c(1803.02, 193.51, 3.47)

Each solution is to be taken with 3 different pipettes (5000, 250 and 10 
µL Volume max) and each of those delivers volumes in steps of 50 µL,  5 
µL  or 1µL, respectively

Since the above values  would eventually become

c(1800, 195, 3)

it is then necessary to recalculate all the final concentrations
of A, B and C, because the volumes are changed.


I know that in most spreadsheets (Calc, Gnumeric, Excel 
and so on) there's a function such as


mround(num; num)

that give the results I need, but I want to learn more on R functions.


I played a little with R functions such as

round, signif, ceiling, trunc, and floor

but without success.
Any hint to solve this problem ?

Thanks a lot

http://www.openofficetips.com/blog/archives/2005/04/rounding_to_the.html
http://www.gnome.org/projects/gnumeric/doc/gnumeric-MROUND.shtml

--
Ottorino-Luca Pantani, Università di Firenze
Dip. Scienza del Suolo e Nutrizione della Pianta
P.zle Cascine 28 50144 Firenze Italia
Tel 39 055 3288 202 (348 lab) Fax 39 055 333 273 
[EMAIL PROTECTED]  http://www4.unifi.it/dssnp/


__
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/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there in R a function equivalent to the mround, as found in most spreadsheets?

2008-05-09 Thread Dieter Menne
Dr. Ottorino-Luca Pantani ottorino-luca.pantani at unifi.it writes:

 
 In a lab experiment I have to mix three solutions to get different 
 concentrations of various molecules in a cuvette
 
 I've used R to calculate the necessary µliters for each of the level of 
 the experiment and I must confess that it is more useful and easier to 
 achieve the results than using spreadsheets.
 
 But there's a problem.
 
 Imagine that for a particular cuvette (I have 112 different cuvettes !!) 
 you have to mix the following volumes of solution A, B, and C respectively.
 
 c(1803.02, 193.51, 3.47)
 
 Each solution is to be taken with 3 different pipettes (5000, 250 and 10 
 µL Volume max) and each of those delivers volumes in steps of 50 µL,  5 
 µL  or 1µL, respectively
 Since the above values  would eventually become
 
 c(1800, 195, 3)
 
 it is then necessary to recalculate all the final concentrations
 of A, B and C, because the volumes are changed.

A first guess would be

a = c(1803.02, 193.51, 3.47)
round(a / 5)*5

which gives

1805  1955

This is not exactly what you want, but it shows that the problem is a bit
ill-defined. In the example you gave, why do you want 1800, and not 1805, which
is possible with the pipettes? I assume that you laboratory experience is
working in the background, telling you to stop pipetmanning when you are close
to the result in some percentage feeling.

Dieter

__
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/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there in R a function equivalent to the mround, as found in most spreadsheets?

2008-05-09 Thread Charilaos Skiadas

On May 9, 2008, at 5:39 AM, Dieter Menne wrote:

Dr. Ottorino-Luca Pantani ottorino-luca.pantani at unifi.it  
writes:


Imagine that for a particular cuvette (I have 112 different  
cuvettes !!)
you have to mix the following volumes of solution A, B, and C  
respectively.


c(1803.02, 193.51, 3.47)

Each solution is to be taken with 3 different pipettes (5000, 250  
and 10
µL Volume max) and each of those delivers volumes in steps of 50  
µL,  5

µL  or 1µL, respectively



Since the above values  would eventually become

c(1800, 195, 3)

it is then necessary to recalculate all the final concentrations
of A, B and C, because the volumes are changed.


A first guess would be

a = c(1803.02, 193.51, 3.47)
round(a / 5)*5

which gives

1805  1955



If I understand the OP's question properly, the first value is to be  
a multiple of 50, the second a multiple of 5, and the third a  
multiple of 1. This can be done with this slight variation on the  
above theme:


a - c(1803.02, 193.51, 3.47)
b - c(50,5,1)
round(a/b) *b

This is not exactly what you want, but it shows that the problem is  
a bit
ill-defined. In the example you gave, why do you want 1800, and not  
1805, which
is possible with the pipettes? I assume that you laboratory  
experience is
working in the background, telling you to stop pipetmanning when  
you are close

to the result in some percentage feeling.

Dieter


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

__
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/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there in R a function equivalent to the mround, as found in most spreadsheets?

2008-05-09 Thread Ottorino-Luca Pantani

Charilaos Skiadas ha scritto:

On May 9, 2008, at 5:39 AM, Dieter Menne wrote:

If I understand the OP's question properly, the first value is to be a 
multiple of 50, the second a multiple of 5, and the third a multiple 
of 1. This can be done with this slight variation on the above theme:


a - c(1803.02, 193.51, 3.47)
b - c(50,5,1)
round(a/b) *b


This is exactly was I was looking for, and you understand it properly.
Sorry for the double post, but I'm experiencing problems with my account 
in this list




This is not exactly what you want, but it shows that the problem is a 
bit
ill-defined. In the example you gave, why do you want 1800, and not 
1805, which
is possible with the pipettes? I assume that you laboratory 
experience is
working in the background, telling you to stop pipetmanning when you 
are close

to the result in some percentage feeling.

Dieter
No, even if there's a lab background working behind, I'm only 
transferring some experience with spreadsheets to R.


I want (actually the pipette wants) 1800 instead that 1805 since the 
larger volumes are to be delivered with a digital pipette whose step is 50.


Thanks to all the people who contributed. This list is always a great 
source.


8rino

__
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/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Is there in R a function equivalent to the mround, as found in most spreadsheets?

2008-05-06 Thread Dr. Ottorino-Luca Pantani

Dear R-users,
I have the following problem

In a lab experiment I have to mix three solutions to get different 
concentrations of various molecules in a cuvette


I've used R to calculate the necessary µliters for each of the level of 
the experiment and I must confess that it is more useful and easier to 
achieve the results than using spreadsheets.


But there's a problem.

Imagine that for a particular cuvette (I have 112 different cuvettes !!) 
you have to mix the following volumes of solution A, B, and C respectively.


c(1803.02, 193.51, 3.47)

Each solution is to be taken with 3 different pipettes (5000, 250 and 10 
µL Volume max) and each of those delivers volumes in steps of 50 µL,  5 
µL  or 1µL, respectively

Since the above values  would eventually become

c(1800, 195, 3)

it is then necessary to recalculate all the final concentrations
of A, B and C, because the volumes are changed.


I know that in most spreadsheets (Calc in Open Office, Gnumeric, Excel 
and so on)

there's a function such as

mround(num; num)

that give the results I need, but I want to learn more on R functions.


I played a little with R functions such as

round, signif, ceiling, trunc, and floor

but without success.
Any hint to solve this problem ?

Thanks a lot

http://www.openofficetips.com/blog/archives/2005/04/rounding_to_the.html
http://www.gnome.org/projects/gnumeric/doc/gnumeric-MROUND.shtml

--
Ottorino-Luca Pantani, Università di Firenze
Dip. Scienza del Suolo e Nutrizione della Pianta
P.zle Cascine 28 50144 Firenze Italia
Tel 39 055 3288 202 (348 lab) Fax 39 055 333 273 
[EMAIL PROTECTED]  http://www4.unifi.it/dssnp/


__
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/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there in R a function equivalent to the mround, as found in most spreadsheets?

2008-05-06 Thread Duncan Murdoch

On 5/6/2008 12:07 PM, Dr. Ottorino-Luca Pantani wrote:

Dear R-users,
I have the following problem

In a lab experiment I have to mix three solutions to get different 
concentrations of various molecules in a cuvette


I've used R to calculate the necessary µliters for each of the level of 
the experiment and I must confess that it is more useful and easier to 
achieve the results than using spreadsheets.


But there's a problem.

Imagine that for a particular cuvette (I have 112 different cuvettes !!) 
you have to mix the following volumes of solution A, B, and C respectively.


c(1803.02, 193.51, 3.47)

Each solution is to be taken with 3 different pipettes (5000, 250 and 10 
µL Volume max) and each of those delivers volumes in steps of 50 µL,  5 
µL  or 1µL, respectively

Since the above values  would eventually become

c(1800, 195, 3)

it is then necessary to recalculate all the final concentrations
of A, B and C, because the volumes are changed.


I know that in most spreadsheets (Calc in Open Office, Gnumeric, Excel 
and so on)

there's a function such as

mround(num; num)

that give the results I need, but I want to learn more on R functions.


I played a little with R functions such as

round, signif, ceiling, trunc, and floor

but without success.
Any hint to solve this problem ?



I believe this function matches the description in OOO:

mround - function(number, multiple) multiple * round(number/multiple)

Duncan Murdoch

__
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/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there in R a function equivalent to the mround, as found in most spreadsheets?

2008-05-06 Thread Yasir Kaheil

Hi Ottorino,
You could just use the modulus operator %% as follows:
 x-c(1803.02, 193.51, 3.47);
 x-x%%c(50,5,1) #just using the modulus operator
[1] 1800  1903

thanks


Dr. Ottorino-Luca Pantani wrote:
 
 Dear R-users,
 I have the following problem
 
 In a lab experiment I have to mix three solutions to get different 
 concentrations of various molecules in a cuvette
 
 I've used R to calculate the necessary µliters for each of the level of 
 the experiment and I must confess that it is more useful and easier to 
 achieve the results than using spreadsheets.
 
 But there's a problem.
 
 Imagine that for a particular cuvette (I have 112 different cuvettes !!) 
 you have to mix the following volumes of solution A, B, and C
 respectively.
 
 c(1803.02, 193.51, 3.47)
 
 Each solution is to be taken with 3 different pipettes (5000, 250 and 10 
 µL Volume max) and each of those delivers volumes in steps of 50 µL,  5 
 µL  or 1µL, respectively
 Since the above values  would eventually become
 
 c(1800, 195, 3)
 
 it is then necessary to recalculate all the final concentrations
 of A, B and C, because the volumes are changed.
 
 
 I know that in most spreadsheets (Calc in Open Office, Gnumeric, Excel 
 and so on)
 there's a function such as
 
 mround(num; num)
 
 that give the results I need, but I want to learn more on R functions.
 
 
 I played a little with R functions such as
 
 round, signif, ceiling, trunc, and floor
 
 but without success.
 Any hint to solve this problem ?
 
 Thanks a lot
 
 http://www.openofficetips.com/blog/archives/2005/04/rounding_to_the.html
 http://www.gnome.org/projects/gnumeric/doc/gnumeric-MROUND.shtml
 
 -- 
 Ottorino-Luca Pantani, Università di Firenze
 Dip. Scienza del Suolo e Nutrizione della Pianta
 P.zle Cascine 28 50144 Firenze Italia
 Tel 39 055 3288 202 (348 lab) Fax 39 055 333 273 
 [EMAIL PROTECTED]  http://www4.unifi.it/dssnp/
 
 __
 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/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 


-
Yasir H. Kaheil, Ph.D.
Catchment Research Facility
The University of Western Ontario 

-- 
View this message in context: 
http://www.nabble.com/Is-there-in-R-a-function-equivalent-to-the-mround%2C-as-found-in-most-spreadsheets--tp17086856p17087399.html
Sent from the R help mailing list archive at Nabble.com.

__
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/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Is there in R a function equivalent to the mround, as found in most spreadsheets?

2008-05-06 Thread hadley wickham

  I believe this function matches the description in OOO:

  mround - function(number, multiple) multiple * round(number/multiple)

I've implemented a slightly more general form in the reshape package:

round_any - function (x, accuracy, f = round) {
f(x/accuracy) * accuracy
}

Hadley

-- 
http://had.co.nz/

__
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/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.