Skip to content
Prev 273203 / 398506 Next

Best method to add unit information to dataframe ?

Hi,

If you want to take advantage of Josh's example below (using an S4
subclass of data.frame), perhaps you might be interested in taking
advantage of the multitude of useful objects/classes defined in the
bioconductor IRanges package:

http://www.bioconductor.org/packages/release/bioc/html/IRanges.html

It has no other bioconductor dependencies, so it's a "slim" install,
in that respect. It defines a DataFrame class which keeps "metadata"
around with as you subset/index/etc. it, eg:

R> library(IRanges)
R> DF <- DataFrame(a=1:10, b=letters[1:10])
R> metadata(DF) <- list(units=list(a=NA, b='inches'))

R> sub.1 <- subset(DF, a %% 2 == 0)
R> sub.1
DataFrame with 5 rows and 2 columns
          a           b
  <integer> <character>
1         2           b
2         4           d
3         6           f
4         8           h
5        10           j

R> metadata(sub.1)
$units
$units$a
[1] NA

$units$b
[1] "inches"

(although I noticed that transform,DataFrame isn't defined actually ...)

Anyway, HTH.

-steve
On Mon, Oct 3, 2011 at 11:15 AM, Joshua Wiley <jwiley.psych at gmail.com> wrote: