[R-sig-Geo] read ascii problem floating point

Clémentine Fritsch clementine.fritsch at univ-fcomte.fr
Mon Jan 24 11:54:21 CET 2011


Hi,

My purpose was to export a x,y,z text file from an ASCII file, and I 
encountered some problems due to floating point. The values of z were 
incorrect in the output file.

I have found a solution with the help of Robert Hijmans and Patrick 
Giraudoux. It is necessary to specify the number of significant digits 
using signif().

For instance:

library(raster)

r<-raster("data.asc")

xyv <- cbind(xyFromCell(r, 1:ncell(r)), v=signif(values(r), digits=2))

write.table(xyv, file="data.txt", row.names=FALSE, sep="\t",dec=".")


Regards,

Clémentine



Clémentine Fritsch a écrit :
> I have tried to read an ascii file using “readAsciiGrid” {maptools} in 
> R 2.12.0. The z values are incorrect, and I strongly suppose that the 
> problem is due to floating point.
>
> Is it possible to specify the number of significant digits in 
> readAsciiGrid?
>
> If not, how could I import my ascii?
>
> Thanks for your help,
>
> Clémentine
>

-- 
Clémentine Fritsch
PhD, post-doc researcher
UMR 6249 - Chrono-Environment
University of Franche-Comte
Place Leclerc
F-25030 Besançon Cedex
FRANCE
E-mail: clementine.fritsch at univ-fcomte.fr
Tel.: +33 (0) 381 665 710
Fax: +33 (0) 381 665 797

-------------- next part --------------
A non-text attachment was scrubbed...
Name: clementine_fritsch.vcf
Type: text/x-vcard
Size: 405 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20110124/90ee5315/attachment.vcf>


More information about the R-sig-Geo mailing list