0
0
R Programmingprogramming~10 mins

Logical operators (&, |, !, &&, ||) in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to perform element-wise logical AND on vectors a and b.

R Programming
result <- a [1] b
Drag options to blanks, or click blank then click option'
A&&
B&
C|
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&&' instead of '&' causes only the first element to be compared.
Using '|' or '||' instead of AND operators.
2fill in blank
medium

Complete the code to perform element-wise logical OR on vectors x and y.

R Programming
result <- x [1] y
Drag options to blanks, or click blank then click option'
A!
B&&
C&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&&' or '&' instead of OR operators.
Using '!' which is logical NOT.
3fill in blank
hard

Fix the error in the code to negate the logical vector v.

R Programming
negated <- [1]v
Drag options to blanks, or click blank then click option'
A!
B&
C&&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&&' or '&' which are AND operators.
Using '|' which is OR operator.
4fill in blank
hard

Fill both blanks to create a vector of TRUE where elements of a are TRUE and elements of b are FALSE.

R Programming
result <- a [1] [2]b
Drag options to blanks, or click blank then click option'
A&
B|
C!
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using '|' instead of '&' for AND operation.
Not negating b before AND.
5fill in blank
hard

Fill all three blanks to create a vector where elements are TRUE if a is TRUE or b is FALSE, but not both.

R Programming
result <- (a [1] ([2]b)) [3] (a [1] b)
Drag options to blanks, or click blank then click option'
A&
B|
C!
D^
Attempts:
3 left
💡 Hint
Common Mistakes
Using AND instead of OR.
Not using XOR to exclude both TRUE.