[R] Column name assignment problem

jim holtman jholtman at gmail.com
Sat Mar 28 00:45:49 CET 2009


Since you want to generate your own variable names instead of using a
list, do the operation in three steps:

x <- get(paste("arunoff_",table_year, sep=''))
colnames(x)[4] <- "COUNT"
assign(paste("arunoff_",table_year, sep=''), x)


On Fri, Mar 27, 2009 at 4:01 PM, Steve Murray <smurray444 at hotmail.com> wrote:
>
> Dear all,
>
> I've been trying to implement the advice given to me, but without much success so far. I thought I'd provide the code in full in the hope that it might make more sense. Just to reiterate, I'm attempting to change the header of the 4th column of every table to "COUNT".
>
>
> year<- 1951:2000
> filelist <- paste("C:\\Data\\arunoff_",year,".txt", sep="")
> filelist
>
>
> # Assign file names to individual objects
>
> table_year=1951
>
> for (i in filelist) {
>          assign(paste("arunoff_",table_year,"_temp", sep=""),read.table(file=i, header=TRUE, sep=","))
>          print(c("LOADED FILE: ","arunoff_",table_year,"_temp"), quote=FALSE)
>          table_year = table_year+1
>          }
>
>
> # RE-FORMAT DATA
>
> # Change names of particular column headings
>          colnames(assign(paste("arunoff_",table_year, sep=""))[4],"COUNT")
>
>
> Any help would be very much appreciated.
>
> Thanks as ever,
>
> Steve
>
> _________________________________________________________________
> [[elided Hotmail spam]]
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list