Skip to content
Prev 273186 / 398506 Next

Best method to add unit information to dataframe ?

On Oct 3, 2011, at 9:35 AM, bruno Piguet wrote:

            
The problem is that there are operations on data frames (e.g. subset()) that will end up stripping your attributes.
'data.frame':	10 obs. of  3 variables:
 $ x: int  1 2 3 4 5 6 7 8 9 10
 $ y: int  11 12 13 14 15 16 17 18 19 20
 $ z: int  101 102 103 104 105 106 107 108 109 110
 - attr(*, "units")= chr  "x_unit" "y_unit"

newDF <- subset(my_frame, x <= 5)
'data.frame':	5 obs. of  3 variables:
 $ x: int  1 2 3 4 5
 $ y: int  11 12 13 14 15
 $ z: int  101 102 103 104 105


You might want to look at either ?comment or the ?label function in Frank's Hmisc package on CRAN, either to use or for example code on how he handles this.

HTH,

Marc Schwartz