2

I have problems multiplying numbers of an external variable in sqldf In the projection of the SQL statement I would like to multiply the value of a column with an external float variable input$euro (e.g. 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)

It seems to me the result is always rounded to 0. My question is also if this is a sensible way to construct the query. The problem might have to do with SQLite.

1 Answers1

2

Try below:

inputEuro <- input$euro
fn$sqldf("select Date, (HeatProduction/3 * $inputEuro) as HeatProduction
          from data
          where Date like '2014%'
          order by Date")

See example 5 for sqldf external variables

zx8754
  • 52,746
  • 12
  • 114
  • 209