Try this:
for (i in 1:100){
filename <- paste("file_", i, ".txt", sep="")
m <- x[((i-1)*256 + 1):(i*256), ]
meta <- paste0("ncols = ", dim(m)[2], ", nrows = ",
dim(m)[1], ", cell
size = ???, etc.")
write.table(meta, filename, row.names=FALSE, col.names=FALSE)
write.table(m, filename, row.names=FALSE, col.names=FALSE, append=TRUE)
}
Jean
On Wed, Jun 19, 2013 at 5:11 AM, Ludovico Frate
<ludovicofrate@hotmail.it>wrote:
> Hi all!
>
> I am using this script to automatically generate txt file (raster map in
> ASCII format) from a big txt file
>
>
>
> 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) }
>
>
>
> I would like to automatically add the same header with information about
> the ASCII (ncols, nrows, cell size, ecc) on every created txt file.
>
> Any suggestion?
>
>
>
> thanks
>
>
>
> Inviata da Windows Mail
> [[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.
>
[[alternative HTML version deleted]]