[R] writing lists fastly on file
Duncan Murdoch
murdoch at stats.uwo.ca
Thu Nov 30 14:27:18 CET 2006
On 11/30/2006 8:19 AM, Milton Cezar Ribeiro wrote:
> In fact I have somethig like
>
> mat.dat<-matrix(rep(c(1,2,4,2,1,0,1,2),128*1024))
> write (mat.dat,"c:\\tmp\\mydat.txt")
>
> * remembering that I will run it about 500,000 times.
>
> The program that I will use to analyze (landscape metrics) my output files read text files ou generic binary files, where I can have each value separated by "space" (text format) or each value into a byte of 8 bits (for beneric binary files). A sample of generic binary is the "RAW" (row and columns) used for Adobe Photoshop. In fact, my matrix of data can be understood as a classifyed image.
The RAW format is probably the fastest to write. Use
writeBin(as.integer(mat.dat), "c:\\tmp\\mydat.raw", size=1). This
writes in column-major order (i.e. column 1, then column 2, etc.). You
need to transpose the matrix before writing if you want row-major order.
Duncan Murdoch
>
> Kind regards,
>
> Miltinho
>
>
> Duncan Murdoch <murdoch at stats.uwo.ca> escreveu:
> On 11/30/2006 6:55 AM, Milton Cezar Ribeiro wrote:
>> Hi there,
>>
>> I have a big amount of "lists" of data, each one with dimension 1024x1024. When I save it in an ASCII file (using "write" function) it take about 15 minutes. As I need run about 500,000 times this same routine, and I would like to do this save task in a fast way.
>
>> In fact I will use these output files in another program that read ASCII or RAW/Generic Binary (8bits) formats. Each value from my lists ranges from 1 to 200 (integer values).
>
> I think this depends on the details. Can you show us what str() gives
> for one of these lists? Can you tell us how flexible the other program
> is about the format of what it needs to see? "RAW/Generic Binary"
> sounds like a format for an image from a digital camera; there might be
> packages available in R that are specifically designed to write that
> format but I don't know them.
>
> Duncan Murdoch
>
>
>
> ---------------------------------
> Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu celular. Registre seu aparelho agora!
More information about the R-help
mailing list