This set of R Programming Language Multiple Choice Questions & Answers (MCQs) focuses on “Overview of R – 3”.
1. What is the class defined in the following R code?
Explanation: Numeric and FALSE is executed as 0. It is somewhat different from other programming languages. Console will give a class as Numeric. A vector can only contain objects of the same class. A list is represented as a vector but can contain objects of different classes.
2. Which one of the following is not a basic datatype?
c) Data frame
Explanation: Data frame is not the basic data type of R. Numeric, character, integer are the basic types of R. The basic data types are used many times. Data frames are used to store tabular data in R. They are an important type of object in R and are used in a variety of statistical modelling applications.
3. How do you create an integer suppose 5 in R?
Explanation: To create an integer L should be added to the integer. L is added to specify that it is an integer. An integer can also be created with many types. If you explicitly want an integer, you need to specify the L suffix.
4. What will be the output of the following R code?
x<- c (“a”,” b”) as.numeric(x)
a)  1 2
b)  TRUE TRUE
c)  NA NA (Warning message: NAs introduced by coercion)
d)  NAN
Explanation: Characters cannot be expressed as numeric. Therefore NA’s are printed as output. NA will specify the missing elements in the list. When nonsensical coercion takes place, you will usually get a warning from R.
5. The dimension attribute is itself an integer vector of length _______
Explanation: It is itself an integer vector of length 2. The dimension attribute in R is an integer vector. Real values larger in modulus than the largest integer are coerced to NA. Matrices are vectors with a dimension attribute. The dimension attribute is itself an integer vector of length 2 (number of rows, number of columns).
6. How could be the matrix constructed by using the following R code?
m <- matrix(1:6, nrow = 2, ncol = 3)
c) any manner
d) data insufficient
Explanation: If nothing is mentioned, matrix is created column-wise. If we want in row-wise then we have to specify. We have to mention “by row” to create a matrix in row wise. The filter( ) function is used to extract subsets of rows from a data frame. This function is similar to the existing subset( ) function.
7. Matrices can be created by row-binding with the help of the following function.
Explanation: rbind() is used to create a matrix by row-binding. Row- binding is the basic function of R. R – bind is used to bind the functions in R. Matrices can be created by column-binding or row-binding with the cbind() and rbind() functions.
8. What is the function used to test objects (returns a logical operator) if they are NA?
Explanation: is.na() is the function used to test if they are NA. We can check NA ‘s at any stage of the code. Generally, We will remove the NA’s for the operations in R like mean etc.., is.na() is used to test objects if they are NA.
9. What is the function used to test objects (returns a logical operator) if they are NaN?
Explanation: is.nan() is used to test if they are NaN. We can check NAN‘s at any stage of the code. We will remove the NA’s for the operations in R. is.nan() is used to test for NaN.
10. What is the function to set column names for a matrix?
d) column name cannot be set for a matrix
Explanation: colnames() is the function to set column names for a matrix. rownames() is the function to set row names for a matrix. But we can’t use both at a time. Column names and row names can be set separately using the colnames() and rownames() functions.
Sanfoundry Global Education & Learning Series – R Programming Language.