Hello, I was wondering if there was an easy way to put information about the measurement units used for each column of a data frame ... Thanks for any pointers, TL
hits=-2.6 tests=BAYES_00 X-USF-Spam-Flag: NO On Thu, 2008-02-07 at 19:32 +0900, Tribo Laboy wrote:> Hello, > > I was wondering if there was an easy way to put information about the > measurement units used for each column of a data frame ... > > Thanks for any pointers, > > TLYou could add attributes: dummy <- data.frame(x = rnorm(10), y = rbeta(10, 2, 5), z = rlnorm(10)) dummy attr(dummy, "units") <- c("m s-2", "Kg", "m") dummy attributes(dummy) G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Here are 3 possibilities where the examples use the builtin data set BOD: #1. Use column headings> names(BOD) <- paste(names(BOD), c("days", "mg/l"), sep = "_") > BODTime_days demand_mg/l 1 1 8.3 2 2 10.3 3 3 19.0 4 4 16.0 5 5 15.6 6 7 19.8 #2. add a "units" attribute to each column> attr(BOD$Time, "units") <- "days" > attr(BOD$demand, "units") <- "mg/l" > attr(BOD$Time, "units")[1] "days" #3. See ?units in the Hmisc package which basically does #2 for you. library(Hmisc) example(units) On Feb 7, 2008 5:32 AM, Tribo Laboy <tribolaboy at gmail.com> wrote:> Hello, > > I was wondering if there was an easy way to put information about the > measurement units used for each column of a data frame ... > > Thanks for any pointers,
On Thu, Feb 7, 2008 at 7:57 PM, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:> > On Thu, 2008-02-07 at 19:32 +0900, Tribo Laboy wrote: > > Hello, > > > > I was wondering if there was an easy way to put information about the > > measurement units used for each column of a data frame ... > > > > Thanks for any pointers, > > > > TL > > You could add attributes: > > dummy <- data.frame(x = rnorm(10), y = rbeta(10, 2, 5), z = rlnorm(10)) > dummy > > attr(dummy, "units") <- c("m s-2", "Kg", "m") > dummy > attributes(dummy) > > G > -- > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% > Dr. Gavin Simpson [t] +44 (0)20 7679 0522 > ECRC, UCL Geography, [f] +44 (0)20 7679 0565 > Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk > Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ > UK. WC1E 6BT. [w] http://www.freshwaters.org.uk > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% > >Hi Gavin, Thanks. That works for me just great. Regrads, TL
Thanks Gabor, In fact I am currently using the first option in your nicely summarized reply. But many of the automatic plotting functions use the column labels for labeling the plots and sometimes it is just a bit inconvenient. Your second option is what Gavin also suggested and I guess I will go with that after having a look at the Hmisc package. Thanks for the help. On Thu, Feb 7, 2008 at 7:59 PM, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> Here are 3 possibilities where the examples use the builtin data set > BOD: > > #1. Use column headings > > > names(BOD) <- paste(names(BOD), c("days", "mg/l"), sep = "_") > > BOD > Time_days demand_mg/l > 1 1 8.3 > 2 2 10.3 > 3 3 19.0 > 4 4 16.0 > 5 5 15.6 > 6 7 19.8 > > #2. add a "units" attribute to each column > > > attr(BOD$Time, "units") <- "days" > > attr(BOD$demand, "units") <- "mg/l" > > attr(BOD$Time, "units") > [1] "days" > > #3. See ?units in the Hmisc package which > basically does #2 for you. > > library(Hmisc) > example(units) > > > > > On Feb 7, 2008 5:32 AM, Tribo Laboy <tribolaboy at gmail.com> wrote: > > Hello, > > > > I was wondering if there was an easy way to put information about the > > measurement units used for each column of a data frame ... > > > > Thanks for any pointers, >