[R] Automatic creation of file names

Greg Snow greg.snow at ihc.com
Thu Sep 22 17:17:11 CEST 2005

Others have shown how to create a vector of names, but here are a
couple of other things you might want to look at.

If you are only using these datasets within R, then you might consider
not saving the data, just the random seeds, then when you need
the data again you can just generate it.

Also look at the g.data package, it provides methods for automatically
saving and loading datasets.

Another option for creating filenames is the tempfile command.

hope this helps,

Greg Snow, Ph.D.
Statistical Data Center, LDS Hospital
Intermountain Health Care
greg.snow at ihc.com
(801) 408-8111

>>> "Leite,Walter" <Walter.Leite at coe.ufl.edu> 09/22/05 08:21AM >>>

Dear R-Help members,

I have a question about how to save to the hard drive the one thousand
datasets I generated in a simulation. The datasets are created in a
"for" loop that repeatedly creates normally distributed datasets, such
as the example below:
for (number in 1:1000) {

dataset = mvrnorm(n = 400, mu = c(0,0,0),
	Sigma = matrix(c(1,0.3,0.3,0.3,1,0.3,0.3,0.3,1),3,3))

I don't know how to write the datasets with different names to the
drive. I have solved the problem before by creating a list of names
(file1.txt, file2.txt,file3.txt, etc...) in Microsoft Excel, reading
to R with read.table, and using write.table to write each file with
name I created in Excel. 
I want to know if it is possible to create a list of file names
automatically within R to save the datasets created in my simulation.
Thank you for your help,

Walter L. Leite

R-help at stat.math.ethz.ch mailing list
PLEASE do read the posting guide!

More information about the R-help mailing list