Spring Cleaning Data: 2 of 6- Changing Column Names and Adding a Column
R-bloggers 2013-04-09
(This article was first published on OutLie..R, and kindly contributed to R-bloggers)
The first post (found here) we downloaded the data and imported it to R using the gdata package. This post we will be changing the column names to make them more reasonable, and adding a quarter variable. The reason for changing the column names is because the dw.2010.q1 file column names are messed up due to the formatting done in Excel. So if I was going to have to change one, just as well change them all, so i did.
The first chunk of code defines the labels I am going to use as c.label. Then I used the colnames() function to rename each file.
#Defining the new labels c.label<-c('loan.date', 'mat.date', 'term', 'repay.date', 'district', 'borrower', 'city', 'state', 'ABA', 'type.credit', 'i.rate', 'amount', 'outstanding.credit', 'total.outstanding', 'collateral', 'commercial', 'residential.morg', 'comm.real', 'consumer', 'treasury', 'municipal', 'corp', 'mbs.cmo', 'mbs.cmo.other', 'asset.backed', 'internat', 'tdfd') #Changing the column names colnames(dw.2010.q3)<-c.label colnames(dw.2010.q4)<-c.label colnames(dw.2011.q1)<-c.label
Created by Pretty R at inside-R.org
To leave a comment for the author, please follow the link and comment on his blog: OutLie..R.
R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series,ecdf, trading) and more...