[R] unit attribute to list elements

From: baptiste Auguié <ba208_at_exeter.ac.uk>
Date: Fri, 28 Dec 2007 19:33:02 +0000


Hi,

I've started my own (first) package, part of which consists in listing common physical constants (Planck's constant, the speed of light in vacuum, etc). I'm wondering what would be a good way of dealing with pairs of value/unit.

> constants <- list( cel = 2.99792458e8 , #m/s
> Z0 = 376.730313461, #ohm
> eps0 = 8.854187817e-12,#F/m
> mu0 = 4*pi*1e-7,#N/A^2
> G = 6.67428e-11 # m^3 kg-1 s-2
> )

I thought I could include the unit in the names attribute of each element, as in :

> names(constants$cel)<- " speed of light in vacuum [m.s^-1]"

Writing this for every element is very redundant... Is there any way to access and set the name of each first level element of the list?

> namesFirstLevelElements(constants)<- c(" speed of light in vacuum
> [m.s^-1]",
> "impedance of vacuum [some unit]",
> ...)

Quite possibly, I'm completely on the wring track;

Many thanks in advance,

baptiste


Baptiste Auguié

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

Phone: +44 1392 264187

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



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. Received on Fri 28 Dec 2007 - 19:37:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 28 Dec 2007 - 22:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.