R Programming Questions and Answers – Reading Datasets – 1

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

Answer: a
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

Answer: d
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)

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

b)

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
[,1] [,2] [,3]
x 1 2 3
y 10 11

c)

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

d)

advertisement
[,4] [,5] [,3]
x 1 3 5
y 4 5 2
View Answer
Answer: a
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
View Answer
Answer: a
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

Answer: c
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"))
View Answer
Answer: b
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

Answer: a
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
View Answer
Answer: a
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

Answer: a
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

Answer: a
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.

To practice all areas of R Programming Language, Here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.