Hi Pete Pete, Try
# option 1 -- 100 files sapply(1:100, function(i){ x <-sample(rnorm(1000, 100, 15), 12, replace = FALSE) write.table(x, paste("sample", i, ".txt", sep = ""), row.names = FALSE, quote = FALSE)) }) # option 2 -- all the information in one file d <- replicate(100, sample(rnorm(1000, 100, 15), 12, replace = FALSE)) write.table(d, "allsamples.txt", sep = "\t", row.names = FALSE, quote = FALSE)) HTH, Jorge On Sat, Sep 3, 2011 at 9:57 AM, Pete Pete <> wrote: > Hi! > > I need to perform this simple sampling function several hundred times: > > x1=as.character(rnorm(1000, 100, 15)) > x2=as.character(rnorm(1000, 150, 10)) > y1=as.data.frame(x1,x2) > > sample1=as.data.frame(sample(y1$x1, 12, replace = FALSE, prob = NULL)) > sample1 > write.table(sample1, "sample1.txt", sep=" ",row.names=F,quote=F) > > My knowledge of loops is quite low. How can I produce 100 loops of the > sampling leading to 100 files from sample1.txt to sample100.txt? > > Thanks for you help! > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Loop-with-random-sampling-and-write-table-tp3787895p3787895.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.