Hi All, I need to write as text files 1000 ish variation of the same data frame, once I permute a row. I would like to use the function write.table() to write the files, and use a loop to do it: for (i in 1:1000){ bb8[2,] = sample(bb8[2,]) write.table(bb8, quote = F, sep = '\t', row.names = F, col.names = F, file = 'whatever?????.txt') } so all the files are called whatever1: whatever1000 Any idea? Cheers, Federico -- Federico C. F. Calboli Department of Epidemiology and Public Health Imperial College, St Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 7594 1602 Fax (+44) 020 7594 3193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] gmail.com
On 5/22/2006 11:24 AM, Federico Calboli wrote:> Hi All, > > I need to write as text files 1000 ish variation of the same data frame, > once I permute a row. > > I would like to use the function write.table() to write the files, and > use a loop to do it: > > for (i in 1:1000){ > > bb8[2,] = sample(bb8[2,]) > write.table(bb8, quote = F, sep = '\t', row.names = F, col.names = F, > file = 'whatever?????.txt') > } > so all the files are called whatever1: whatever1000 > > Any idea?Use the paste() function to construct the name, e.g. file = paste("whatever",i,".txt", sep="") Duncan Murdoch
On Mon, 2006-05-22 at 16:24 +0100, Federico Calboli wrote:> Hi All, > > I need to write as text files 1000 ish variation of the same data frame, > once I permute a row. > > I would like to use the function write.table() to write the files, and > use a loop to do it: > > for (i in 1:1000){ > > bb8[2,] = sample(bb8[2,]) > write.table(bb8, quote = F, sep = '\t', row.names = F, col.names = F, > file = 'whatever?????.txt') > } > so all the files are called whatever1: whatever1000 > > Any idea? > > Cheers, > > FedericoThe same process used in R FAQ 7.34: How can I save the result of each iteration in a loop into a separate file? can be used here. Instead of using save(), use write.table(), adjusting the arguments accordingly. HTH, Marc Schwartz
Federico Calboli wrote:> Hi All, > > I need to write as text files 1000 ish variation of the same data frame, > once I permute a row. > > I would like to use the function write.table() to write the files, and > use a loop to do it: > > for (i in 1:1000){ > > bb8[2,] = sample(bb8[2,]) > write.table(bb8, quote = F, sep = '\t', row.names = F, col.names = F, > file = 'whatever?????.txt') > } > so all the files are called whatever1: whatever1000 > > Any idea? > > Cheers, > > Federico >This is the FAQ "How can I save the result of each iteration in a loop into a separate file?" Please read the FAQs prior to posting! Uwe Ligges