[R] Labelling all variables at once (using Hmisc label)

Frank Harrell f.harrell at vanderbilt.edu
Tue Aug 16 13:22:07 CEST 2011


Do require(Hmisc); ?label to see the help file for label.  It will show you
how to do this:


Monsieur Do wrote:
> 
> The labels can contain much more than just names. In my case, they are
> variable descriptions (items from a questionnaire). I need to keep the
> names as they are, hence the need for Hmisc's labels.
> 
> On Mon, Aug 15, 2011 at 3:53 PM, Monsieur Do
> <nonaupourriel at yahoo.ca> wrote:
>> I have a dataset and a list of labels. I simply want
> to apply the labels to the variables, all at once. The only way I was able
> to
> do it was using a loop:
>> 
>>     for (i in
> 1:length(data))  label(data[,i]) <-
> data.labels[i]
>> 
>> I'd like to find the non-loop way to do it, using
> apply or the like... Any help appreciated.
>  
> Would you not be better off with names()?
>  
>> data <- 1:10
>> data.labels <- letters[1:10]
>> names(data) <- data.labels
>> data
>  a  b  c  d  e  f  g  h  i  j
>  1  2  3  4  5  6  7  8  9 10
>  
> What are you trying to do with label() that names()
> doesn't accomplish?
>  
> -- 
> Sarah Goslee
> http://www.functionaldiversity.org
> 	[[alternative HTML version deleted]]
> 
> 
> ______________________________________________
> 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 Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: http://r.789695.n4.nabble.com/Labelling-all-variables-at-once-using-Hmisc-label-tp3745660p3746928.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list