[R] importing numeric types via sqlQuery
jim holtman
jholtman at gmail.com
Mon Oct 11 22:28:25 CEST 2010
I would assume that the digitis are not being chopped off. It is just
that R will typically print data to 7 significant digits:
> x <- 54469517.307692307692
> x
[1] 54469517
> options(digits=20)
> x
[1] 54469517.3076923
>
Your data it there and you can set 'options' to show it if you want
to. Also with floating point, you will only get about 15 digits of
accuracy (see FAQ 7.31).
On Mon, Oct 11, 2010 at 4:19 PM, E C <mmmraspberries at hotmail.com> wrote:
>
> Hi everyone,
> I am using the sqlQuery function (in RODBC library) to import data from a database into R. My table (called temp) in the database looks like this:
> category numabc 54469517.307692307692def 36428860.230769230769
> I used the following R code to pull data into R:data <-sqlQuery(channel, "select category, num from temp;")
> However, the result is that "num" gets all its decimal places chopped off, so "data" looks like this instead in R:category numabc 54469517def 36428860
>
> I've tried various alternative approaches, but none have fixed the problem. When I cast the variable to a numeric type like this (data <-sqlQuery(channel, "select category, num::numeric from temp;"), it still gave me the same result. Casting to a real type like this (data <-sqlQuery(channel, "select category, num::real from temp;") resulted in scientific notation that also rounded the numbers.
> Any suggestions? Much appreciated!
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list