[R] practical way to change column names?

PIKAL Petr petr.pikal at precheza.cz
Tue Aug 28 10:25:42 CEST 2012


Hi

sufix<-expand.grid(c("id","ag"), 1:10)
paste(paste("alter",sufix[,1], sep=""), sufix[,2], sep="_")

shall give you desired names.

After that you can reorganise it to suit your needs.

Regards
Petr


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Niklas Fischer
> Sent: Monday, August 27, 2012 6:50 PM
> To: r-help at r-project.org
> Subject: [R] practical way to change column names?
> 
> Dear R helpers,
> I have a social network data including repated measures of ten alters
> (whom you contact) and their attributes(gender, age, strength of tie).
> 
> I wrote variables related with alters just for wrote alter 1 and alter
> 2.
> 
> I'd like to change the like below. I'd change each name separetely.
> 
> Do you know any pratical way to change it?
> All the bests,
> Niklas
> 
> variables for alter 1
> g61a (id)
> g62a (gender)
> g63a (age)
> g63aa (tie)
> g63aan (tie friequency)
> 
> variables for alter 2
> g61b
> g62b
> g63b
> g64b
> g64bb
> g64bbn
> 
> new names
> 
> alterid_1
> alterag_1
> alteraa_1
> alatert_1
> altersf_1
> 
> alterid_2
> alterag_2
> alteraa_2
> alatert_2
> altersf_2
> 
> 	[[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.




More information about the R-help mailing list