0

While calculating SMI() function from TTR Package in R using RStudio, often this error is given: "Error in hmax - lmin : non-numeric argument to binary operator". But after simply closing RStudio - and saving all the workspace - and starting it again, when this function is run, No error is given.

Sample Data:-

> head(a)
# A tibble: 6 × 7
  Date       Time   Open  High   Low Close Volume
  <chr>      <chr> <dbl> <dbl> <dbl> <dbl>  <dbl>
1 2012.06.19 14     1.26  1.26  1.26  1.26   4518
2 2012.06.19 15     1.26  1.26  1.26  1.26   5668
3 2012.06.19 16     1.26  1.27  1.26  1.27   5696
4 2012.06.19 17     1.27  1.27  1.27  1.27   5742
5 2012.06.19 18     1.27  1.27  1.27  1.27   3477
6 2012.06.19 19     1.27  1.27  1.27  1.27   4751

The line of code that gives this error (often):-

c = as.data.frame(SMI(a[, c("High", "Low", "Close")]))

Error:-

Error in hmax - lmin : non-numeric argument to binary operator
Abdul Basit Khan
  • 646
  • 1
  • 6
  • 19
  • I had a similar problem but when I checked class(df) where df was my tibble, it showed actually three classes where 'dataframe' was one of them. Then I did df <- as.data.frame(df). After that, Class(df) gave onle 'dataframe' and SMI calculations went smoothly without error. My initial df was aslo a tibble from a SELECT SQL Server query of analogues to yours stock data which I keep in SQL Server table. – Adam Jul 18 '23 at 20:14

0 Answers0