为什么两个数值相除,结果为零?在 R 中使用 SQLDF
Why two numeric divide, the result is zero? using SQLDF in R
我在 R 中使用 SQLDF。我从第 2 列和第 3 列计算两个不同的值。我想计算第 2 列/第 3 列,但结果始终为零。为什么?
这是我的代码:
prouterInboundin4hours<-sqldf(
" select `1st Segment Delivered Success Day`, count (DISTINCT case when
`Inbound Lead Time (hour)` < 4 then `First segment Order Number` END)
as 'Inbound< 4 hours Volume',
count (`First segment Order Number`) as 'Delivered Success Volume',
count (DISTINCT case when `Inbound Lead Time (hour)` < 4 then `First
segment Order Number` END) / count (`First segment Order Number`)
from prouter
where Year ='Year2017'
group by `1st Segment Delivered Success Day`
"
)
结果是:
与在 R 中不同,如果您将两个整数相除,您将得到另一个整数。比较这两个:
sqldf("select 1/2")
## 1/2
## 1 0
sqldf("select cast (1 as real)/2")
## cast (1 as real)/2
## 1 0.5
我在 R 中使用 SQLDF。我从第 2 列和第 3 列计算两个不同的值。我想计算第 2 列/第 3 列,但结果始终为零。为什么?
这是我的代码:
prouterInboundin4hours<-sqldf(
" select `1st Segment Delivered Success Day`, count (DISTINCT case when
`Inbound Lead Time (hour)` < 4 then `First segment Order Number` END)
as 'Inbound< 4 hours Volume',
count (`First segment Order Number`) as 'Delivered Success Volume',
count (DISTINCT case when `Inbound Lead Time (hour)` < 4 then `First
segment Order Number` END) / count (`First segment Order Number`)
from prouter
where Year ='Year2017'
group by `1st Segment Delivered Success Day`
"
)
结果是:
与在 R 中不同,如果您将两个整数相除,您将得到另一个整数。比较这两个:
sqldf("select 1/2")
## 1/2
## 1 0
sqldf("select cast (1 as real)/2")
## cast (1 as real)/2
## 1 0.5