You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that in the episode "Making Choices" the operators && and || are used while & and | are not introduced. I think in the examples given, these operators can be used interchangeably. Still, I wonder if it might be better to use the latter two.
The reason is that this lesson stresses vectorisation and the use of && and || can lead to unexpected results when used on vectors.
While & and | return pairwise comparisons for each vector index,
> c(T, F) & c(T, T)
[1] TRUE FALSE
&& and || compare only the first elements of both vectors. So, the fact that the second elements are not both true is missed here:
> c(T, F) && c(T, T)
[1] TRUE
See also ?base::Logic
Hope this is helpful.
Hannes
The text was updated successfully, but these errors were encountered:
Hi there,
I noticed that in the episode "Making Choices" the operators
&&
and||
are used while&
and|
are not introduced. I think in the examples given, these operators can be used interchangeably. Still, I wonder if it might be better to use the latter two.The reason is that this lesson stresses vectorisation and the use of
&&
and||
can lead to unexpected results when used on vectors.While
&
and|
return pairwise comparisons for each vector index,&&
and||
compare only the first elements of both vectors. So, the fact that the second elements are not both true is missed here:See also
?base::Logic
Hope this is helpful.
Hannes
The text was updated successfully, but these errors were encountered: