Skip to content
Prev 140697 / 398506 Next

problem with white space

Here is one way of doing it.  I would suggest that you read in the
data with readLines and then combine into one single string so that
you can use substring on it.  Since you did not provide  provide
commented, minimal, self-contained, reproducible code, I will take a
guess at that your data looks like:

# create some test data -- might be read in the readLines
sdata <- sapply(1:10, function(x){  # 10 lines of strings with 50 characters
    paste(sample(LETTERS, 50, TRUE), collapse='')
})
# put into one large string so you can do substring on it
sdata <- paste(sdata, collapse='')
# now create 10 sample of size 20 and write in files (file1, file2, ... file10)
for (i in 1:10){
    x <- sample(nchar(sdata), 20)
    writeLines(paste(substring(sdata, x, x), collapse=''),
con=paste("file", i, sep=''))
}





On Sun, Mar 30, 2008 at 3:41 PM, Suraaga Kulkarni
<suraaga.kulkarni at gmail.com> wrote: