R Programming MCQ Questions And Answers - Functions
This section focuses on "Functions" in R Programming. These Multiple Choice Questions (MCQ) should be practiced to improve the R Programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. An R function is created by using the keyword?
A. fun
B. function
C. declare
D. extends
View Answer
Ans : B
Explanation: An R function is created by using the keyword function.
2. What will be output for the following code?
print(mean(25:82))
A. 1526
B. 53.5
C. 50.5
D. 55
View Answer
Ans : B
Explanation: The code will find mean of numbers from 25 to 82 that is 53.5
3. Point out the wrong statement?
A. Functions in R are “second class objects”
B. The writing of a function allows a developer to create an interface to the code, that is explicitly specified with a set of parameters
C. Functions provides an abstraction of the code to potential users
D. Writing functions is a core activity of an R programmer
View Answer
Ans : A
Explanation: Functions in R are “first class objects”, which means that they can be treated much like any other R object.
4. What will be output for the following code?
> paste("a", "b", se = ":")
A. a+b
B. a:b
C. a-b
D. None of the above
View Answer
Ans : D
Explanation: With the paste() function, the arguments sep and collapse must be named explicitly and in full if the default values are not going to be used.
5. Which function in R language is used to find out whether the means of 2 groups are equal to each other or not?
A. f.tests ()
B. l.tests ()
C. t.tests ()
D. p.tests ()
View Answer
Ans : C
Explanation: t.tests () function in R language is used to find out whether the means of 2 groups are equal to each other. It is not used most commonly in R. It is used in some specific conditions.
6. What will be the output of log (-5.8) when executed on R console?
A. NA
B. NAN
C. 0.213
D. Error
View Answer
Ans : B
Explanation: Executing the above on R console or terminal will display a warning sign that NaN (Not a Number) will be produced in R console because it is not possible to take a log of a negative number(-).
7. Which 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
Ans : 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().
8. How will you check if an element is present in a vector?
A. Match()
B. Dismatch()
C. Mismatch()
D. Search()
View Answer
Ans : A
Explanation: It can be done using the match () function- match () function returns the first appearance of a particular element. The other way is to use %in% which returns a Boolean value either true or false.
9. You can check to see whether an R object is NULL with the _________ function.
A. is.null()
B. is.nullobj()
C. null()
D. as.nullobj()
View Answer
Ans : A
Explanation: It is sometimes useful to allow an argument to take the NULL value, which might indicate that the function should take some specific action.
10. In the base graphics system, which function is used to add elements to a plot?
A. Boxplot()
B. Text()
C. Treat()
D. Both A and B
View Answer
Ans : D
Explanation: In the base graphics system, boxplot or text function is used to add elements to a plot.
Discussion