result_create(conn @ ptr,statement):结果太大

时间:2018-12-16 18:38:42

标签: r linear-regression sqldf

t1_DA <- sqldf("select decile, 
               count(decile) as count, avg(pred_spent) as avg_pred_spent,   
               avg(exp(total_spent)) as avg_total_spent,
               avg(log(pred_spent)) as ln_avg_pred_spent,   
               avg(total_spent) as ln_avg_total_spent
               from t1
               group by decile
               order by decile desc")

我正在对文件进行线性回归,当我运行这部分代码时,我得到了错误提示

  

result_create(conn @ ptr,语句)中的错误:结果太大

有什么办法可以克服这个错误?

1 个答案:

答案 0 :(得分:1)

如前所述,默认情况下,sqldf使用SQLite语言,该语言不支持explog等广泛的数学和统计功能。诚然,更好的提示信息可以帮助用户调试而不是结果太大(对于作者@ggrothendieck可能是git issue)。

但是,为了将这些输出集成到汇总查询中,请考虑在sqldf中运行之前创建这些列。使用transformwithin可以轻松进行新的列分配,而无需使用$分配方法不断引用数据框。

t1 <- transform(t1, exp_total_spent = exp(total_spent),
                    log_pred_spent = log10(log_pred_spent)
                )
# ALTERNATIVE
t1 <- within(t1, {exp_total_spent <- exp(total_spent)
                  log_pred_spent <- log10(log_pred_spent)
             })

t1_DA <- sqldf("select decile, 
                       count(decile) as count, 
                       avg(pred_spent) as avg_pred_spent,   
                       avg(exp_total_spent) as avg_total_spent,
                       avg(log_pred_spent) as ln_avg_pred_spent,   
                       avg(total_spent) as ln_avg_total_spent
                from t1
                group by decile
                order by decile desc")