[R] performing script on multiple files

2010-09-24 Thread Jonas Josefsson
say that I have a script that uses read.csv to read a textfile in a certain directory, then transforming the data a bit and then spit out a new file in an output directory. Is it possible to make this universal so the same procedure is made for all files in a certain directory and also make it

Re: [R] performing script on multiple files

2010-09-24 Thread Phil Spector
Jonas - Here's an (untested) idea: readwrite = function(file,outputdirectory){ dat = read.csv(file) . . . write.csv(dat,file = paste(outputdirectory,sub('\\.csv','.new',file),sep='/')) } sapply(list.files('.',pattern='\\.csv$'),readwrite,'/some/location') It will read