Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use of && vs & -- instructor training contribution #540

Open
hannesbecher opened this issue Apr 1, 2022 · 0 comments
Open

use of && vs & -- instructor training contribution #540

hannesbecher opened this issue Apr 1, 2022 · 0 comments

Comments

@hannesbecher
Copy link

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,

> 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant