0
0
R Programmingprogramming~20 mins

Logical (boolean) type in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Logical Mastery in R
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of logical operations in R
What is the output of the following R code?
R Programming
x <- c(TRUE, FALSE, TRUE)
y <- c(FALSE, FALSE, TRUE)
result <- x & y
print(result)
A[1] TRUE TRUE TRUE
B[1] TRUE FALSE TRUE
C[1] FALSE FALSE TRUE
D[1] FALSE TRUE FALSE
Attempts:
2 left
💡 Hint
Remember that '&' is element-wise AND in R.
Predict Output
intermediate
2:00remaining
Result of logical negation in R
What will be printed by this R code?
R Programming
flag <- c(TRUE, FALSE, FALSE, TRUE)
neg_flag <- !flag
print(neg_flag)
A[1] FALSE FALSE FALSE FALSE
B[1] FALSE TRUE TRUE FALSE
C[1] TRUE FALSE FALSE TRUE
D[1] TRUE TRUE TRUE TRUE
Attempts:
2 left
💡 Hint
The '!' operator flips TRUE to FALSE and vice versa.
Predict Output
advanced
2:00remaining
Logical vector recycling in R
What is the output of this R code snippet?
R Programming
a <- c(TRUE, FALSE)
b <- c(TRUE, TRUE, FALSE, FALSE)
result <- a | b
print(result)
A[1] TRUE FALSE TRUE FALSE
B[1] TRUE TRUE TRUE TRUE
C[1] TRUE TRUE FALSE FALSE
D[1] TRUE TRUE TRUE FALSE
Attempts:
2 left
💡 Hint
Remember R recycles shorter vectors to match the length of longer vectors.
Predict Output
advanced
2:00remaining
Logical indexing with boolean vectors in R
What will this R code print?
R Programming
values <- c(10, 20, 30, 40, 50)
filter <- c(TRUE, FALSE, TRUE, FALSE, TRUE)
selected <- values[filter]
print(selected)
A[1] 10 30 50
B[1] 20 40
C[1] 10 20 30 40 50
D[1] 30 50
Attempts:
2 left
💡 Hint
Logical vectors can be used to pick elements from another vector.
🧠 Conceptual
expert
2:00remaining
Understanding the difference between '&' and '&&' in R
Which statement best describes the difference between '&' and '&&' in R?
A'&' performs element-wise logical AND on vectors; '&&' evaluates only the first element of each vector.
B'&' performs logical OR; '&&' performs logical AND.
C'&' and '&&' are interchangeable and produce the same result for all inputs.
D'&' is used only for single logical values; '&&' works on vectors element-wise.
Attempts:
2 left
💡 Hint
Think about how R treats vectorized logical operations versus single comparisons.