R Programming Questions and Answers – Overview of R – 2

This set of R Programming Language Multiple Choice Questions & Answers (MCQs) focuses on “Overview of R – 2”.

1. What will be the output of the following R program?

r<-0:10
r[2]

a) 0
b) 1
c) 2
d) 3
View Answer

Answer: b
Explanation: 1 is the output of the above code as indexing in R starts from 1. The output can be viewed in the R console. R studio has both R terminal and the R console. Each output format is implemented as a function in R. You can customize the output by passing arguments to the function as sub-values of the output field.
advertisement
advertisement

2. Which of the following operator is used to create integer sequences?
a) :
b) ;
c) –
d) ~
View Answer

Answer: a
Explanation: “:” operator is used to create an integer sequence. The other operators are used for other purposes. Integer sequence is the basic operator used in R. The [ operator can be used to extract multiple elements of a vector by passing the operator an integer sequence.

3. What will be the output of the following R program?

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
        y<-0:5
 	vector(y)
 	y[3]

a) Error in vector(y): invalid ‘mode’ argument
b) 1
c) 4
d) 3
View Answer

Answer: a
Explanation: y is already vector; second line is an invalid argument. The third line will give us the output. When an R vector is printed you will notice that an index for the vector is printed in square brackets
[] on the side.

advertisement

4. In R language, a vector is defined that it can only contain objects of the ________
a) Same class
b) Different class
c) Similar class
d) Any class
View Answer

Answer: a
Explanation: A vector can only contain objects of the same class. A vector cannot have contain objects of the different class. Same class objects are used mostly. The most basic type of R object is a vector. Empty vectors can be created with the vector() function.

5. A list is represented as a vector but can contain objects of ___________
a) Same class
b) Different class
c) Similar class
d) Any class
View Answer

Answer: b
Explanation: A list can contain objects of different class. But a vector can only contain objects of the same class. A vector cannot have contain objects of the different class. Same class objects are used mostly.
advertisement

6. How can we define ‘undefined value’ in R language?
a) Inf
b) Sup
c) Und
d) NaN
View Answer

Answer: d
Explanation: NaN is used to define the “undefined” value in the R language. Undefined values also have some value in R. Missing values are denoted by NA or NaN for q undefined mathematical operations. A NaN value is also NA but the converse is not true.

7. What is NaN called?
a) Not a Number
b) Not a Numeric
c) Number and Number
d) Number a Numeric
View Answer

Answer: a
Explanation: NaN is called Not a Number. It is the full form of NaN. Full forms can be viewed in R studio by typing help. A NaN value is also NA but the converse is not true. The value NaN represents an undefined value.

8. How can we define ‘infinity’ in R language?
a) Inf
b) Sup
c) Und
d) NaN
View Answer

Answer: a
Explanation: Inf is used to define “Infinity” in R. It is somewhat different from other programming languages. There is also a special number of Inf which represents infinity.

9. What will be the output of the following R code?

y <- c(TRUE, 2)

a) [1] “TRUE” “2”
b) [1] “TRUE” 2
c) [1] “0” “2”
d) [1] 1 2
View Answer

Answer: d
Explanation: Here TRUE is taken as 1. Then it will give output as 1 and 2. FALSE can be taken as 0. T and F are short-hand ways to specify TRUE and FALSE.

10. What is the class defined by the following R code?

y<-c(2,”t)

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

Answer: a
Explanation: Here 2 is changed into character. Since the y belongs to list. A list contains only characters. Combining a numeric object with a character object will create a character vector because numbers can usually be easily represented as strings.

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.

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.