[R] Physical Units in Calculations

S Ellison S.Ellison at lgc.co.uk
Mon Apr 13 22:10:49 CEST 2009


Another issue with units is 'recognising' things. For example, Hz are
also s^-1 ...

S

>>> Stavros Macrakis <macrakis at alum.mit.edu> 04/13/09 9:38 AM >>>
On Sun, Apr 12, 2009 at 11:01 PM,  <Bill.Venables at csiro.au> wrote:
> It is, however, an interesting problem and there are the tools there
to handle it.  Basically you need to create a class for each kind of
measure you want to handle ("length", "area", "volume", "weight", and so
on) and then overload the arithmetic operators so that they can handle
arguments of the appropriate class.

I'd think it would be far simpler and cleaner to have a single
dimensioned-units class with a slot for magnitude and one for the
power of each dimension -- M, L, T are uncontroversial, pick your
system for electromagnetism and thermodynamics....  Once you have
that, you have not just mass, length, and time, but also area, volume,
density, acceleration, viscosity, etc. etc.

It would of course be nice if the existing difftime class could be fit
into this, as it is currently pretty much a second-class citizen.  For
example, c of two time differences is currently a numeric vector,
losing its units (hours, days, etc.) completely.

One of the difficulties of adding units would be, I suspect, making
them work nicely with the rest of the system.  For example, although
sum is defined abstractly in terms of '+', as far as I can tell
sum.units would have to be overloaded explicitly. Similarly for mean,
cumsum, rle, var, %*%, etc. etc.

              -s

______________________________________________
R-help at 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.


*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}




More information about the R-help mailing list