[R] Text file: multiple matrix

Purna chander chanderbio at gmail.com
Wed Oct 10 06:32:44 CEST 2012


Hi,

You can try this and see. I'm assuming that the initial text file
named "test.txt".

x<-read.table("test.txt",header=T)  # if headers are present in "test.txt"
      or
x<-read.table("test.txt")

# Actually, read.table() command skips the blank lines.

n<-256

for (i in 1:100){
  filename=paste("file_",i,".txt",sep="")
  m<-x[((i-1)*256+1):(i*256),]
  write.table(m,filename,row.names=F,col.names=F)
}

Regards,
Purna


On 10/9/12, ludovico <ludovicofrate at hotmail.it> wrote:
> Hi there! I'm a newbie in R
> This is my problem: I have a txt file composed by 100 matrix (256x256)
> separated by a blank line! How can I save automatically the matrix in
> separated txt file (100)?
> e.g.
> 1° matrix from line 1 to line 256
> 257 blank line
> 2°matrix from line 258 to line 513
> 514 blank line
> 3° matrix from line 515 to line 770
> 771 blank line
> 4° matrix from line 772 to line 1027......
> Thanks
>
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Text-file-multiple-matrix-tp4645551.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>




More information about the R-help mailing list