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?
Explanation: An R function is created by using the keyword function.
2. What will be output for the following code?
Explanation: The code will find mean of numbers from 25 to 82 that is 53.5
3. Point out the wrong statement?
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 = ":")
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?
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?
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?
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?
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.
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?
Explanation: In the base graphics system, boxplot or text function is used to add elements to a plot.