[R] attributes of a data.frame
Adrian DUSA
adi at roda.ro
Mon Nov 21 20:51:31 CET 2005
On Monday 21 November 2005 22:41, Duncan Murdoch wrote:
> [...snip...]
> Not all dataframes have the variable.labels attribute. I'm guessing
> you've installed some contributed package to add them, or are importing
> an SPSS datafile using read.spss. So don't expect varlab() or
> variable.labels() function to be a standard R function.
Aa-haa... of course you are right: I read them via read.spss. I understand.
Now, just to the sake of it, would it be wrong to make it standard?
Is there a special reason not to?
> If you want to define it, definitions like this should work (but I can't
> test them):
>
> varlab <- function(foo) attr(foo, "variable.labels")
>
> "varlab<-" <- function(foo, label, value) {
> attr(foo, "variable.labels")[label] <- value
> foo
> }
>
> Use them like this:
>
> varlab(x) # to see the labels
>
> varlab(x, "varname") <- "label" # to set one
>
> Duncan Murdoch
Thank you for the tip; I'll certainly use it.
Adrian
--
Adrian DUSA
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
+40 21 3120210 / int.101
More information about the R-help
mailing list