0

I am trying to get a signal using ifelse in R, but , when comparing two xts objects, I get a subscript out of bounds error, even though they have the same number of rows and columns, and don't contain any NAs. The code is as follows:

Max_cl :
2017-01-03
29.0375
225.24
2017-01-04
29.0375
226.58
2017-01-05
29.1525
226.58
2017-01-06
29.4775
227.21
2017-01-09
29.7475
227.21
2017-01-10
29.7775
227.21
2017-01-11
29.9375
227.21
2017-01-12
29.9375
227.21
2017-01-13
29.9375
227.21
2017-01-17
30.0000
227.21
cl:
2017-01-03
29.0375
225.24
2017-01-04
29.0050
226.58
2017-01-05
29.1525
226.40
2017-01-06
29.4775
227.21
2017-01-09
29.7475
226.46
2017-01-10
29.7775
226.46
2017-01-11
29.9375
227.10
2017-01-12
29.8125
226.53
2017-01-13
29.7600
227.05
2017-01-17
30.0000
226.25
toSig <- lag(ifelse(lag(max_cl) <= cl,1,NA))

I don't have dplyr loaded, and I have tried using the stats::lag but I keep getting the same error. Thanks in advance for the help !

Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
  • That's a lot of `lag`s in there... – cory Oct 14 '22 at 17:19
  • 1
    Would you please provide your actual xts objects making use of `dput()` and edit your question? Would be much easier to assist if your code was actually reproducible. Thanks! – dimfalk Oct 19 '22 at 08:22

0 Answers0