0

Sorry about my last lengthy post. Here is a more condensed problem that I am running into with the all function.

As an example, below you can see my console output in which the all function seems to only check whether the last element of x satisfies the all condition.

>   x
 [1] 0.7583398 0.8352907 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333 0.8683173 0.8683173 0.7004333
[15] 0.7004333 0.8683173 0.8683173 0.8683173 0.7004333 0.7004333 0.7004333 0.7004333 0.8683173 0.8683173 0.7004333 0.7004333 0.7004333 0.7004333
[29] 0.7004333 0.8683173 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333 0.8683173 0.7004333 0.7004333 0.8683173 0.7004333 0.7004333 0.7004333
[43] 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333 0.8683173 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333
[57] 0.8683173 0.7004333 0.8683173 0.7004333 0.7004333 0.7004333 0.8683173 0.8683173 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333
[71] 0.8683173 0.7004333 0.7004333 0.7004333 0.7004333 0.8683173 0.7004333 0.7004333 0.7004333 0.7004333 0.7004333 0.8683173 0.8683173
> x1[t]
[1] 0.7004333
> x2[t]
[1] 0.8683173
> x3[t]
[1] 0.8683173
> all(c(x1[t],x2[t], x3[t]) %in% x)
[1] FALSE
> all(c(x2[t],x2[t], x3[t]) %in% x)
[1] TRUE
> all(c(x1[t],x1[t], x1[t]) %in% x)
[1] FALSE
Nate River
  • 51
  • 6
  • You are searching for floating point values, which may not be stored exactly as you think. – Tim Biegeleisen Mar 28 '20 at 05:07
  • Thank you for the response, but Im not sure if I am (i just read the post you linked)... Im trying to set a conditional that just see's if values ```x1[t],x2[t].x3[t]``` are all at any point present in the vector x. If the problem was about floating values, why is it the case that when all the values in the all function (as above in console) are the same, the ```all``` function is ```TRUE```? Sorry I am just not sure how the floating point values going – Nate River Mar 28 '20 at 05:34
  • 1
    The point here, e.g. in the case of the first call to `all()`, is that it _looks_ like all three values are present in `x`, but this is not actually the case. – Tim Biegeleisen Mar 28 '20 at 05:35
  • My question is, then, how do I make it such that all numbers are checked, and not just the last element of the vector? The only recommendation I can think of based on the link you sent me is that I round all of the objects and vectors, but this doesn't seem to help if the ```all``` function for some reason is only checking whether the objects match the last element of the vector ```x``` – Nate River Mar 28 '20 at 05:36
  • 1
    One option: Just compare the first X places of precision. – Tim Biegeleisen Mar 28 '20 at 05:36
  • Thank you for the link, your suggestions, and your patience. I think hopefully the rounding has done to trick. – Nate River Mar 28 '20 at 06:06

0 Answers0