[R] How many attributes are there of a variable?
Frank E Harrell Jr
f.harrell at vanderbilt.edu
Sun Sep 6 23:21:15 CEST 2009
Peng,
You can create all the attributes you want, with one headache: R does
not keep attributes across subsetting operations so you need to write
classes and "[.something" methods when attributions need to be kept or
adjusted upon subsetting rows.
The Hmisc package uses attributes such as label, units, imputed. You
might look at the code to see how it did that. For example, label(x)
will use attr(x, 'label') to fetch the 'label' attribute. There are
attribute-setting functions there too.
Frank
Peng Yu wrote:
> Hi,
>
> According to the example below this email, attr(x,"names") is the same
> as names(x). I am wondering how many attributes there are of a given
> variable. How to find out what they are? Can I always use
> some_attribute(x) instead of attr(x, "some_attribute")?
>
> Regards,
> Peng
>
>> x=c(1,2,3)
>> attr(x,"names")=c("a","b","c")
>> x
> a b c
> 1 2 3
>> y=c(1,2,3)
>> names(y)=c("a","b","c")
>> y
> a b c
> 1 2 3
>
> ______________________________________________
> 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.
>
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
More information about the R-help
mailing list