我在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`
"
)
结果是:
答案 0 :(得分:5)
与R不同,如果划分两个整数,则得到另一个整数。比较这两个:
sqldf("select 1/2")
## 1/2
## 1 0
sqldf("select cast (1 as real)/2")
## cast (1 as real)/2
## 1 0.5