Re: [R] Decimals in R/SQL

From: jim holtman <jholtman_at_gmail.com>
Date: Wed, 13 Apr 2011 12:15:31 -0400

You at least have to provide a subset of 'ss09' so we can see what the original data looks like. I have not had any problems with decimals in using sqldf.

> x <- as.data.frame(matrix(runif(100)*100, 10))
> x$key <- sample(1:3, 10, TRUE)

> require(sqldf)
> xsum <- sqldf('

+     select key, sum(V1 * V2) / sum(V3)
+         from x
+         group by key
+ ')

>
>
> xsum

  key sum(V1 * V2) / sum(V3)
1   1               19.38166
2   2               17.40503
3   3               71.48818

> dput(xsum)

structure(list(key = 1:3, `sum(V1 * V2) / sum(V3)` = c(19.3816573628268, 17.4050302312273, 71.4881812227571)), .Names = c("key", "sum(V1 * V2) / sum(V3)" ), row.names = c(NA, 3L), class = "data.frame")
>

On Wed, Apr 13, 2011 at 11:10 AM, Rachel Licata <RachelL_at_kff.org> wrote:
> Hello,
>
> When I am writing in sqldf or RSQLite I lose the decimals in my matrix.
> The only way I can get decimals is by multiplying by 1.00000, etc.  I
> have tried manipulating the options, but it is only effective once I
> multiply by 1.0000.
>
> I appreciate any suggestions!
>
> Thanks!
>
> Example:
>
> z <- sqldf ("select ST,
> SUM(AGEP*PWGTP)*1.000000000/SUM(PWGTP)*1.00000000000000 as wgtage from
> ss09 group by ST")
>
> z shouldn't be whole numbers.
>
>
>        [[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
Data Munger Guru

What is the problem that you are trying to solve?

______________________________________________
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.
Received on Wed 13 Apr 2011 - 16:18:33 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 13 Apr 2011 - 16:50:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive