2
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")

I am doing linear regression on a file and when I run this part of the code I am getting following error

Error in result_create(conn@ptr, statement) : Result too large

Is there any way to overcome this error?

markus
  • 25,843
  • 5
  • 39
  • 58
Random user
  • 33
  • 1
  • 7

1 Answers1

1

As mentioned, by default sqldf uses the SQLite dialect which does not support extensive mathematical and statistical functions like exp and log. Admittedly, a better raised message can help users debug rather than Result too large (maybe a git issue for author, @ggrothendieck?).

However, in order to integrate these outputs into your aggregate query, consider creating those columns before running in sqldf. Use either transform or within for easy new column assignment without constant reference to data frame using the $ assignment approach.

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")
Parfait
  • 104,375
  • 17
  • 94
  • 125