On Tue, 5 Dec 2006, Yoni Schamroth wrote:
> Hi,
>
> I am attempting to query a data frame from a mysql database.
> One of the variables is a unique identification number
("numeric") 18 digits
> long.
> I am struggling to retrieve this variable exactly without any rounding.
Read it as a character - a double is a double:
> x <- 6527600583317876352
> y <- 6527600583317876380
> all.equal(x,y)
[1] TRUE> storage.mode(x)
[1] "double"
and why they are equal is a FAQ (only ~16 digits in a double). Integer is
4-byte. Since they are IDs, not to be used for math, leave them as
character strings - which they are, like telephone numbers.
>
> The function I am using is sqlQuery(), with an ODBC connection.
> Querying directly results in the double being rounded towards the end (eg
> 6527600583317876352 instead of 6527600583317876380)
>
> Is there anyway of preserving the "numeric" class of the variable
and it
> precision without converting it to a factor? Is the double stored as a
> 64-bit integer?
>
> I have attempted to use the 'dec' as well as 'as.is =
TRUE', both
> automatically convert it to a factor which I am trying to avoid.
>
> Any advice or assistance would be greatly appreciated.
>
> Thanks
>
> Yoni Schamroth
> Director of Research
> MediaBoost LTD
> Tel. +972-3-5333033 (ext. 105)
> Fax.?+972-3-5480617
> Mob.?+972-52-3422204
> yoni.schamroth at compile-inc.com
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no