Re: [R] How to change all name of variables

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 02 Jun 2005 - 23:21:35 EST

On 6/2/05, Muhammad Subianto <subianto@gmail.com> 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.

Try this:

names(prima) <- paste("xyz", names(prima), sep = ".")



R-help@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 Received on Thu Jun 02 23:31:40 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:21 EST