[R] Output multiple files

Muhammad Rahiz muhammad.rahiz at ouce.ox.ac.uk
Mon Dec 7 18:42:53 CET 2009


Hello,

I want the ouput to take the name of the original file. I have the following code - but the problem is that the output overrides the original file which I desire not.

So given an input file called File1.txt, I want the ouput to be called File1.out.txt, or something along this line. I'm working with many files, fyi.

out=c("file1.txt", "file2.txt", "file3.txt")
for (i in 1:3){               # where 3 is the number of files
file[[i]] <- file[[i]] * 3   # just a simple calculation to multiply the matrix by 3
write.table(file[[i]],out[i], row.names=FALSE, col.names=FALSE)
}

Thanks.

-- 
Muhammad Rahiz  |  Doctoral Student in Regional Climate Modeling					
Climate Research Laboratory, School of Geography & the Environment	
Oxford University Centre for the Environment
South Parks Road, Oxford, OX1 3QY, United Kingdom 
Tel: +44 (0)1865-285194	 Mobile: +44 (0)7854-625974
Email: muhammad.rahiz at ouce.ox.ac.uk




More information about the R-help mailing list