Hi,

Two thoughts I'd like to share on this subject:


1) Something really cool for conversions between units is the Google search bar: type in " 3 inches in cm" and you get,
        
3 inches = 7.62 centimeters

or, " 3 £ in dollar",

3 UK£ = 4.4007 U.S. dollars

or "12 cubic meters to pints",

12 (cubic meters) = 21 117.0391 Imperial pints

That is a very clever pattern recognition, and very useful for this task.

I think a similar implementation would be great to facilitate the use of units within R, I'm not sure Google has shared the code though.


2) the Grid package provides the unit() functions that handles conversions between different systems (inches, cm, pts, ...). I'm sure Paul Murrell thought a lot about the best implementation for this (I'm guessing he is the author of that function),

getAnywhere(valid.unit)

function (x, units, data)
{
    valid.units <- valid.units(units)
    data <- valid.data(rep(units, length.out = length(x)), data)
    attr(x, "unit") <- units
    attr(x, "valid.unit") <- valid.units
    attr(x, "data") <- data
    class(x) <- "unit"
    x
}



so we could imagine these two functions,

convert(12, from= "m^3", to = "pint", round=FALSE)


or,

unit(12, "m^3") + unit(3, "pint")



Note that lengths (perhaps also time and color to a minor extent) are especially important in that it's the only actual physical dimension rendered in a final plot, the others are put in correspondence (isomorphism between continuous variables) with the labels set accordingly.

Best wishes,

baptiste




On 13 Apr 2009, at 01:00, Tom La Bone wrote:


Back in 2005 I had been doing most of my work in Mathcad for over 10 years. For a number of reasons I decided to switch over to R. After much effort and help from you folks I am finally "thinking" in R rather than thinking in Mathcad and trying to translating to R. Anyway, the only task I still use Mathcad for is calculations that involve physical quantities and units. For example, in Mathcad I can add 1 kilometer to 1 mile and get the right answer in the units of length I choose. Likewise, if I try to add 1 kilometer to 1 kilogram I get properly chastised. Is there a way in R to assign quantities
and units to numbers and have R keep track of them like Mathcad does?

Tom
--
View this message in context: 
http://www.nabble.com/Physical-Units-in-Calculations-tp23016092p23016092.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.

_____________________________

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

______________________________________________
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.

Reply via email to