This set of R Programming Language Multiple Choice Questions & Answers (MCQs) focuses on “Reading Datasets – 1”.
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()
View Answer
Explanation: 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
View Answer
Explanation: 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
Explanation: 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
Explanation: 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
View Answer
Explanation: 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"))
Explanation: 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
View Answer
Explanation: 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)
no yes 2 3
b)
yes no 2 3
c)
no yes 2 2
d)
yes yes 6 2
Explanation: 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)
View Answer
Explanation: 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
View Answer
Explanation: Missing values are denoted by NA or NaN for q undefined mathematical operations.
Sanfoundry Global Education & Learning Series – R Programming Language.
Here’s the list of Best Books in R Programming Language.
- Check R Programming Books
- Apply for Programming Internship
- Check Information Technology Books
- Practice Programming MCQs