250+ TOP MCQs on Reading Datasets and Answers

R Programming Language Multiple Choice Questions on “Reading Datasets”.

1. The ________ function takes an arbitrary number of arguments and concatenates them one by one into character strings.
a) copy()
b) paste()
c) bind()
d) del()

Answer: a
Clarification: Any numbers given among the arguments are coerced into character strings in the evident way, that is, in the same way they would be if they were printed.

2. Point out the correct statement?
a) Character strings are entered using either matching double (“) or single (‘) quotes
b) Character vectors may be concatenated into a vector by the c() function
c) Subsets of the elements of a vector may be selected by appending to the name of the vector an index vector in square brackets
d) All of the mentioned

Answer: d
Clarification: Character quantities and character vectors are used frequently in R.

3. What will be the output of the following R code?

> x <- 1:3
> y <- 10:12
> rbind(x, y)

a)

[,1] [,2] [,3]
x 1 2 3
y 10 11 12

b)

[,1] [,2] [,3]
x 1 2 3
y 10 11

c)

[,1] [,2] [,3]
x 1 2 3
y 4 5 6

d)

[,4] [,5] [,3]
x 1 3 5
y 4 5 2

View Answer

Answer: a
Clarification: rbind() function combines vector, matrix or data frame by rows.

 

4. What will be the output of the following R code?

> x <- list(1, "a", TRUE, 1 + 4i)
> x

a)

[[1]]
[1] 1
 
[[2]]
[1] "a"
 
[[3]]
[1] TRUE
 
[[4]]
[1] 1+4i

b)

[[1]]
[1] 2
 
[[2]]
[1] "b"
 
[[3]]
[1] TRUE
 
[[4]]
[1] 1+4i

c)

[[1]]
[1] 3
 
[[2]]
[1] "a"
 
[[3]]
[1] TRUE
 
[[4]]
[1] 1+4i

d)

[[1]]
[1] 77
 
[[2]]
[1] "a"
 
[[3]]
[1] False
 
[[4]]
[1] 1+5i

View Answer

Answer: a
Clarification: Lists can be explicitly created using the list() function, which takes an arbitrary number of arguments.

 

5. Point out the wrong statement?
a) matrices or more generally arrays are multi-dimensional generalizations of vectors
b) factors provide compact ways to handle categorical data
c) vectors provide a convenient way to return the results of a statistical computation
d) lists can be explicitly created using the list() function

  250+ TOP MCQs on ggplot2 and Answers

Answer: c
Clarification: The dimension attribute is itself an integer vector of length 2 (number of rows, number of columns).

6. Which of the following is valid assignment?
a)

 > x <- fact(c("yes", "yes", "no", "yes", "no"))

b)

 > x <- factor(c("yes", "yes", "no", "yes", "no"))

c)

 > x <- factor(factor("yes", "yes", "no", "yes", "no"))

d)

 > x <- factor(factor("yes", "no", "no", "yes", "no"))

View Answer

Answer: b
Clarification: Factor objects can be created with the factor() function.

 

7. What will be the output of the following R code?

> x <- vector("list", length = 5)
> x

a) NULL
b) 1
c) 0
d) 4

Answer: a
Clarification: We can also create an empty list of a pre-specified length with the vector() function.

8. What will be the output of the following R code?

> x <- factor(c("yes", "yes", "no", "yes", "no"))
> table(x)

a)

b)

c)

d)

View Answer

Answer: a
Clarification: The order of the levels of a factor can be set using the levels argument to factor().

 

9. Which of the following code snippet will create a vector with NAs in it?
a) x >- c(1, 2, NA, 10, 3)
b) x >- cNA(1, 2, NA, 10, 3)
c) x >- NA(1, 2, NA, 10, 3)
d) x >- NA(1, 5, NA, 10, 8)

Answer: a
Clarification: This returns a logical vector indicating which elements are NA.

10. What will be the output of the following R code?

> x <- c(1, 2, NaN, NA, 4)
> is.na(x)

a) FALSE FALSE TRUE TRUE FALSE
b) FALSE TRUE TRUE TRUE FALSE
c) TRUE FALSE TRUE TRUE FALSE
d) TRUE FALSE TRUE FALSE FALSE

  250+ TOP MCQs on Scoping Rules and Answers

Answer: a
Clarification: Missing values are denoted by NA or NaN for q undefined mathematical operations.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top