[R] How to change all name of variables

Muhammad Subianto subianto at gmail.com
Thu Jun 2 17:22:32 CEST 2005


Dear all R-helpers,
Thanks you very much for your help. I would like to thanks Sean Davis 
and Gabor Grothendieck for their help.
Best wishes, Muhammad Subianto


On this day 6/2/2005 3:21 PM, Gabor Grothendieck wrote:
 >
 > Try this:
 >
 > names(prima) <- paste("xyz", names(prima), sep = ".")
 >

On this day 6/2/2005 1:20 PM, Sean Davis wrote:
 > See ?paste.
 >
 > Something like below if you have 100 column names:
 >
 > dimnames(pima.tr)[[2]] <-
 > paste(rep('xyz',100),dimnames(pima.tr)[[2]],sep=".")
 >
 > You probably want to test the paste statement before setting the
 > dimnames, or operate on a copy of the data until you get the hang of
 > using paste.
 >
 > Sean


On this day 6/2/2005 1:04 PM, Muhammad Subianto wrote:
> Dear R-helpers,
> First I apologize if my question is quite simple
> I have a large datasets which more 100 variables.
> For a research I need to change all name of variables with add one or
> more letters on each variables.
> For example,
>  > data(Pima.tr)
>  > Pima.tr[1:5,]
>   npreg glu bp skin  bmi   ped age type
> 1     5  86 68   28 30.2 0.364  24   No
> 2     7 195 70   33 25.1 0.163  55  Yes
> 3     5  77 82   41 35.8 0.156  35   No
> 4     0 165 76   43 47.9 0.259  26   No
> 5     0 107 60   25 26.4 0.133  23   No
>  >
>  > dimnames(Pima.tr)[[2]]
> [1] "npreg" "glu"   "bp"    "skin"  "bmi"   "ped"   "age"   "type"
>  >
> 
> I need to change the variables name ,
> "npreg" "glu" "bp" "skin" "bmi" "ped" "age" "type"
> with
> "xyz.npreg" "xyz.glu" "xyz.bp" "xyz.skin" "xyz.bmi" "xyz.ped" "xyz.age" 
> "xyz.type"
> 
> How can I make this (automatically). I don't want to make manual with 
> more 100 variables.
> I  would be very happy if anyone could help me.
> Thank you for your time.
> Kindly regards, Muhammad Subianto
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list