[R] Adding columns to csvs in a loop

Jim Holtman jholtman at gmail.com
Tue Mar 20 11:42:59 CET 2012


for (i in fileList){
  x <- read.csv(i)
  x$QID <- ""
  x$COMMENTS <- ""
  x$"DATE CREATED" <- ""
  write.csv(x, file = i)
}

Sent from my iPad

On Mar 19, 2012, at 17:42, Edgar Alminar <eaalminar at ucsd.edu> wrote:

> Hello,
> I am trying to add columns to a folder of csvs (the folder is called "20120314"). 
> I have csvs of different numbers of columns, but at the end of this loop, I'd like to add three columns to each csv: "QID", "COMMENTS", "DATE CREATED".
> I've tried some things with cbind, I looked at using awk, but I couldn't get either to work.
> 
> Does anyone have an example of a working loop that adds columns to a folder of csvs?
> 
> Thanks!
> Edgar
> ______________________________________________
> 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.



More information about the R-help mailing list