R Programming Coding MCQ Questions

Welcome to R Programming Coding MCQ Questions. Here, we present 20 MCQs (Multiple-Choice Questions) with code snippets to test your understanding of R programming coding and logical stills. Let's get started!

1. What will be the output of the following R program?

print(class(42L))
a) "numeric"
b) "integer"
c) "double"
d) "number"

2. What does this R code snippet output?

x <- 8
y <- 3
print(x %% y)
a) 2
b) 2.67
c) 3
d) None of the above

3. Consider the following R code. What will it print?

x <- 10
change <- function(x) {
    x <- 20
}
change(x)
print(x)
a) 10
b) 20
c) 0
d) NULL

4. What is the output of the following R function?

s1 <- "hello"
s2 <- "hello"
print(s1 == s2)
a) TRUE
b) FALSE
c) NULL
d) Error

5. What will this R program output?

print("5" + 2)
a) Error
b) "52"
c) "7"
d) "5 + 2"

6. Analyze the following R code snippet. What is its output?

print(class(10.5))
a) "numeric"
b) "double"
c) "integer"
d) "float"

7. Consider the following R code. What will it print?

i <- 0
print(i <- i + 1)
a) 0
b) 1
c) Error
d) NULL

8. What does this R code output?

x <- 5
print(if (x > 3) "Yes" else "No")
a) Yes
b) No
c) 1
d) 0

9. What will the following R code print?

numbers <- c(1, 2, 3)
print(length(numbers))
a) 3
b) 2
c) 1
d) NULL

10. What does the following R program output?

x <- 5
y <- 10
x <- y
print(x, y)
a) 5 10
b) 10 5
c) 10 10
d) NULL

11. Analyze the following R code snippet. What will it output?

s <- "hello"
print(substr(s, 2, 3))
a) he
b) el
c) llo
d) ell

12. What will the following R code output?

print(toupper("Hello"))
a) HELLO
b) hello
c) Hello
d) Error

13. Consider the following R code. What will it print?

result <- 10 / 4
print(result)
a) 2.5
b) 2
c) 2.0
d) None of the above

14. What is the output of the following R function?

print(gsub("b", "2", "abc"))
a) a2c
b) abc
c) ac
d) ab2c

15. What will this R program output?

flag <- 10 > 9 && 5 > 4
print(flag)
a) TRUE
b) FALSE
c) Error
d) NULL

16. What does the following R code snippet output?

array <- c(1, 2, 3)
array[2] <- 10
print(array)
a) c(1, 10, 3)
b) c(1, 2, 3)
c) Error
d) NULL

17. Consider the following R code. What will it print?

s <- "Hello"
t <- s
t <- paste(t, "World")
print(s)
a) Hello World
b) Hello
c) HelloHello
d) Error

18. What does the following R code output?

m <- c(a=1, b=2)
m['c'] <- 3
print(length(m))
a) 2
b) 3
c) Error
d) NULL

19. What will the following R code print?

x <- 1
for(i in 1:5) {
    x <- x * 2
}
print(x)
a) 2
b) 16
c) 32
d) 64

20. What does this code snippet output?

print(nchar("Hello"))
a) 5
b) Error
c) "Hello"
d) None of the above

Comments