[R] Labelling all variables at once (using Hmisc label)
    Sarah Goslee 
    sarah.goslee at gmail.com
       
    Mon Aug 15 23:03:51 CEST 2011
    
    
  
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
    
    
More information about the R-help
mailing list