R Programming Questions and Answers – Functions – 6

This set of R Programming Language Multiple Choice Questions & Answers (MCQs) focuses on “Functions – 6”.

1. R code can be tested using _________________ package.
a) Dplyr
b) Hadley’s testthat
c) SKLearn
d) KNN
View Answer

Answer: b
Explanation: R code can be tested using Hadley’s testthat package. Testthat draws inspiration from the xUnit family of testing packages, as well as from many of the innovative ruby testing libraries.

2. If the programmers want the output to be a data frame or a vector, then ________ function is used.
a) Lapply
b) Sapply
c) Vapply
d) Zapply
View Answer

Answer: a
Explanation: If the programmers want the output to be a data frame or a vector, then sapply function is used whereas if the programmer wants the output to be a list then lapply is used. vapply allows the programmer to specific the output type.

3. If a programmer wants the output to be a list then ___________ function is used.
a) Lapply
b) Sapply
c) Vapply
d) Zapply
View Answer

Answer: b
Explanation: sapply() function does the same jobs as lapply() function but returns a vector. We can use a user built-in function into lapply() or sapply(). We create a function named avg to compute the average of the minimum and maximum of the vector.
advertisement
advertisement

4. _____________ function is preferred over sapply as vapply allows the programmer to specific the output type.
a) Lapply
b) Japply
c) Vapply
d) Zapply
View Answer

Answer: c
Explanation: Vapply is similar to sapply, but has a pre-specified type of return value, so it can be safer (and sometimes faster) to use. simplify2array() is the utility called from sapply() when simplify is not false and is similarly called from mapply().

5. Which function is difficult to implement?
a) Lapply
b) Japply
c) Vapply
d) Zapply
View Answer

Answer: c
Explanation: Vapply allows the programmer to specific the output type. The disadvantage of using vapply is that it is very difficult to be implemented and more verbose. vapply is similar to sapply, but has a pre-specified type of return value, so it can be safer to use.

6. Which function is more verbose?
a) Lapply
b) Japply
c) Vapply
d) Zapply
View Answer

Answer: c
Explanation: If a programmer wants the output to be a list then lapply is used. vapply allows the programmer to specific the output type. The disadvantage of using vapply is that it is very difficult to be implemented and more verbose.

7. _____________ will produce a sequential vector c( (1,2,3,4,5,6,7,8,9)).
a) Seq(9)
b) Seq(10)
c) Seq(15)
d) Seq(12)
View Answer

Answer: a
Explanation: Seq generates a sequence of a priori known pattern. Seq_along(6) will produce a vector with length 6 whereas seq(6) will produce a sequential vector from 1 to 6 c((1,2,3,4,5,6)).
advertisement

8. __________ function is used for reading the .csv file in R language.
a) Write.csv()
b) Read.csv ()
c) Let.csv()
d) Table.csv()
View Answer

Answer: b
Explanation: read.csv () function is used for reading the .csv file in R language. We will use the built in the read.csv() function call, which reads the data as the data frame, and assign the data frame to a variable.

9. The line of code in R language should begin with a ________________
a) Hash symbol
b) Alphabet
c) Number
d) Character
View Answer

Answer: a
Explanation: The line of code in R language should begin with a hash symbol (#). R has a large number of in-built functions and also the user can create their own functions.
advertisement

10. _______________ returns TRUE then X can be termed as a matrix data object.
a) is.”matrix(X”)
b) is.matrix(X)
c) is.notamatrix(X )
d) is.matrix(“X”)
View Answer

Answer: b
Explanation: The function call is.matrix(X ) returns TRUE then X can be termed as a matrix data object. R has a large number of in-built functions and also the user can create their own functions.

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.