[R] Apply vector of labels to columns of data frame

Steve Powell steve at promente.org
Fri Oct 5 12:51:16 CEST 2007


Thanks Shubha, Petr and Patrick - 
Erm, yes perhaps I wasn't clear, when I said "label" I didn't mean names, I
meant the labels provided by Hmisc. 
So for example
v=c("lab1","lab2","lab3")
a<-b<-c<-1:3
df=data.frame(cbind(a,b,c))

I can do 
label(df$a)="lab1"
label(df$b)="lab2" etc
Or 
attributes(df$a)$label="lab1" etc
But I would like to do this with a loop or an apply function.
Thanks and best wishes


Steve Powell
 
proMENTE social research 
research | evaluation | training & consulting
 
Kranjčevićeva 35, 71000 Sarajevo 
mobile: +387 61 215 997 | office: +387 33 556 865 | fax: +387 33 556 866
skype: stevepowell99 
www.promente.org

 

-----Original Message-----
From: Patrick Burns [mailto:pburns at pburns.seanet.com] 
Sent: 05 October 2007 11:50
To: Steve Powell
Subject: Re: [R] Apply vector of labels to columns of data frame

Your question is not very clear, but is this what you want:

colnames(v) <- paste('lab', 1:ncol(v), sep='')


Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

Steve Powell wrote:

>Dear list members
>I would like to apply a vector of labels
>v=c("lab1","lab2","lab3")
>to a dataframe
>df=data.frame(1:3,1:3,1:3)
>using some kind of loop or apply function.
>Any ideas?
>Thanks
> 
>
>Steve Powell
>
>
>
>Checked by AVG Free Edition. 
>
>17:03
> 
>
>	[[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.
>
>
>  
>

No virus found in this incoming message.
Checked by AVG Free Edition. 

04.10.2007
17:03
 


Checked by AVG Free Edition. 

04.10.2007
17:03
 



More information about the R-help mailing list