Hi, I guess this is pretty basic. I have 25 variables in the data file (name: score), i.e. X1,X2,.....,X25. I dont want to use score$X1, score$X2 everytime I use these variables. Is there a way I can rename all these variables as simply X1,X2,.....X25 without writing 25 lines of code, one line for renaming each variable (eg: > X1=score.X1 >X2=score.X2 and so on) ? Thanks for your help. Regards, Preetam -- Preetam Pal (+91)-9432212774 M-Stat 2nd Year, Room No. N-114 Statistics Division, C.V.Raman Hall Indian Statistical Institute, B.H.O.S. Kolkata. [[alternative HTML version deleted]]
You haven't said yet, what object your 'data file' is. If you mean a data.frame I would use colnames(dataName) <- c("Col1Name", "col2Name", ?.) Best Simon On Sep 20, 2013, at 4:10 PM, Preetam Pal <lordpreetam at gmail.com> wrote:> Hi, > > I guess this is pretty basic. > > I have 25 variables in the data file (name: score), i.e. X1,X2,.....,X25. > > I dont want to use score$X1, score$X2 everytime I use these variables. > > Is there a way I can rename all these variables as simply X1,X2,.....X25 > without writing 25 lines of code, one line for renaming each variable (eg: >> X1=score.X1 >X2=score.X2 and so on) ? > > Thanks for your help. > > Regards, > Preetam > > -- > Preetam Pal > (+91)-9432212774 > M-Stat 2nd Year, Room No. N-114 > Statistics Division, C.V.Raman > Hall > Indian Statistical Institute, B.H.O.S. > Kolkata. > > [[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.
On Fri, Sep 20, 2013 at 10:10 AM, Preetam Pal <lordpreetam@gmail.com> wrote:> I have 25 variables in the data file (name: score), i.e. X1,X2,.....,X25. > > I dont want to use score$X1, score$X2 everytime I use these variables. >attach(score) plot(X1, X2) # etc. etc. -Aaron [[alternative HTML version deleted]]
Depending on what your doing perhaps with() could help? Or assuming a data.frame or matrix, score[ , 25] will give you Score$X25 If you would supply a bit more information (and code) about what you are doing we probably can help more. John Kane Kingston ON Canada> -----Original Message----- > From: lordpreetam at gmail.com > Sent: Fri, 20 Sep 2013 19:40:23 +0530 > To: r-help at r-project.org > Subject: [R] Renaming variables > > Hi, > > I guess this is pretty basic. > > I have 25 variables in the data file (name: score), i.e. X1,X2,.....,X25. > > I dont want to use score$X1, score$X2 everytime I use these variables. > > Is there a way I can rename all these variables as simply X1,X2,.....X25 > without writing 25 lines of code, one line for renaming each variable > (eg: > > X1=score.X1 >X2=score.X2 and so on) ? > > Thanks for your help. > > Regards, > Preetam > > -- > Preetam Pal > (+91)-9432212774 > M-Stat 2nd Year, Room No. > N-114 > Statistics Division, C.V.Raman > Hall > Indian Statistical Institute, B.H.O.S. > Kolkata. > > [[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.____________________________________________________________ Receive Notifications of Incoming Messages Easily monitor multiple email accounts & access them with a click. Visit http://www.inbox.com/notifier and check it out!