所以,我有这段代码,其中我将数据从mysql传递到nodejs到r-script,但是,它说
“未找到对象'total_sales''
这是我的js文件中的代码:
var getSales = function() {
const db = require('../db.js')
let sql = 'SELECT * FROM sales_tbl'
db.query(sql, (error, results, fields) => {
if (error) throw error
console.log(results);
var out = R("./public/salesforecast.R")
.data(results)
.callSync();
console.log(out);
return out
})
}
console.log(getSales());
这是r脚本文件salesforecast.R:
x <- c(total_sales)
s <- as.numeric(12)
numfore <- as.numeric(12)
K <- s
nx <- length(x)
nxmK <- nx - K
x <- ts(x, frequency = s)
fit <- HoltWinters(x, seasonal = 'additive')
p <- predict(fit, numfore, prediction.interval = TRUE)