Skip to content
Prev 307435 / 398506 Next

Text file: multiple matrix

Hello,

Try the following, substituting your filename for "test.txt".


fun <- function(filenumber, con, n, sep = " ", prefix = "RTest"){
     txt <- readLines(con, n = n)
     tc <- textConnection(txt)
     on.exit(close(tc))
     tbl <- read.table(tc, sep = sep)[-n, ]
     filename <- sprintf("%s_%03d", prefix, filenumber)
     write.table(tbl, filename, row.names = FALSE)
     filename
}

NRows <- 256
NMat <- 100
fc <- file("test.txt", open = "rb")
lapply(seq_len(NMat), fun, fc, n = NRows + 1)
close(fc)


Hope this helps,

Rui Barradas

Em 09-10-2012 11:15, ludovico escreveu: