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
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
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
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.
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
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
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
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
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)).
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
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
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.
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
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 .
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Check Information Technology Books
- Practice Programming MCQs
- Check R Programming Books
- Apply for Programming Internship