我在 sqldf 中乘以外部变量的数字时遇到问题 在 SQL 语句的投影中,我想将列的值与外部浮点变量 input$euro 相乘(例如 0.23)。
data <- read.csv("consumption1.csv", sep=",", header=T,skip =1)
colnames(data)[1] <- "Date"
colnames(data)[2] <- "HeatProduction"
sqldf("select Date, (HeatProduction/3*'%f') as HeatProduction from data where Date like '2014%' order by Date", input$euro)
在我看来,结果总是四舍五入为 0。我的问题还在于这是否是构建查询的明智方法。该问题可能与 SQLite 有关。
最佳答案
尝试以下:
inputEuro <- input$euro
fn$sqldf("select Date, (HeatProduction/3 * $inputEuro) as HeatProduction
from data
where Date like '2014%'
order by Date")
关于r - 如何使用外部浮点变量在 sqldf 语句中进行乘法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27878025/