[R] column name handling and long labels

Frank E Harrell Jr f.harrell at vanderbilt.edu
Wed Feb 27 19:15:36 CET 2008


Werner Wernersen wrote:
> Somehow, I don't get how the labels of Hmisc work. My
> expectation was that if I use the following code and
> then the print method, I would get an output where the
> headers are replaced by the labels but I get the
> normal variable names. How can I get the labels as
> headers instead in the printed table?
> 
> df <- data.frame(x=seq(1,3),y=seq(4,6))
> df <- upData(df, labels=c(x="X1",y="X2"))
> print(df2)
> 
> Thanks again,
>   Werner

The labels are generally too long for printing.  They are instead used 
for axis labels in plotting and for various statistical tables (e.g. 
those generated by summary.formula).  Above all they are used for fully 
annotating data frames (see the contents and describe function).

Frank

> 
>>> Hi,
>>>
>>> I have two loosely related questions which could
>> make
>>> my live again a bit easier:
>>>
>>> 1) Is there a simple way to select a range of
>> columns
>>> in a data frame using column names?
>>> I am thinking of something like
>> mydf[1,"col4":"col8"]
>>
>> Try this using builtin data frame anscombe which has
>> columns
>> x1 to x4 followed by y1 to y4:
>>
>> subset(anscombe, select = x3:y2)
>>
>>> 2) I have a data frame with many columns and they
>> all
>>> have short variable names which is good in most
>> cases
>>> but sometimes it would be nice to have also a
>> longer
>>> descriptive name / label attached to the variable
>>> which could then be used for printing and latex
>>> output. Has anybody come up with a convenient way
>> to
>>> do that?
>>> Right now, I am using always match or merge in
>> case of
>>> row names.
>>>
>> See ?label in package Hmisc.
>>
>>> Many thanks,
>>>  Werner
> 
> 
> 
>       Lesen Sie Ihre E-Mails auf dem Handy.
> 
> ______________________________________________
> 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