R Programming Questions and Answers – Overview of R – 3

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?

    y<-c(FALSE,2)

a) Character
b) Numeric
c) Logical
d) Integer
View Answer

Answer: b
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.
advertisement
advertisement

2. Which one of the following is not a basic datatype?
a) Numeric
b) Character
c) Data frame
d) Integer
View Answer

Answer: c
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?
a) 5L
b) 5l
c) 5i
d) 5d
View Answer

Answer: a
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] 1 2
b) [1] TRUE TRUE
c) [1] NA NA (Warning message: NAs introduced by coercion)
d) [1] NAN
View Answer

Answer: c
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.
advertisement

5. The dimension attribute is itself an integer vector of length _______
a) 1
b) 2
c) 3
d) 4
View Answer

Answer: b
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).
advertisement

6. How could be the matrix constructed by using the following R code?

 m <- matrix(1:6, nrow = 2, ncol = 3)

a) row-wise
b) column-wise
c) any manner
d) data insufficient
View Answer

Answer: b
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.
a) rjoin()
b) rbind()
c) rowbind()
d) rbinding()
View Answer

Answer: b
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?
a) is.na()
b) is.nan()
c) as.na()
d) as.nan()
View Answer

Answer: a
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?
a) as.nan()
b) is.na()
c) as.na()
d) is.nan()
View Answer

Answer: d
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?
a) names()
b) colnames()
c) col.names()
d) column name cannot be set for a matrix
View Answer

Answer: b
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.

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.