[R] Automatic creation of file names

Hao Chen hchen at utmem.edu
Thu Sep 22 16:28:25 CEST 2005


On Thu, Sep 22, 2005 at 10:21:06AM -0400, Leite,Walter wrote:
> 
> 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:
> Library(MASS)
> 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 hard
> drive. I have solved the problem before by creating a list of names
> (file1.txt, file2.txt,file3.txt, etc...) in Microsoft Excel, reading it
> to R with read.table, and using write.table to write each file with the
> 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.

paste("file", 1:1000, ".txt", sep="")

> Thank you for your help,
> 
> Walter L. Leite
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

-- 
-
: Hao Chen, Ph.D.

: Instructor 
: Department of Pharmacology
: University of Tennessee Health Science Center
: Memphis, TN 38163 USA
: Office: 901 448 3201
: Mobil:  901 826 1845 

Mining PubMed: http://www.chilibot.net
-




More information about the R-help mailing list