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
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.
2. Which of the following operator is used to create integer sequences?
a) :
b) ;
c) –
d) ~
View Answer
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?
y<-0:5 vector(y) y[3]
a) Error in vector(y): invalid ‘mode’ argument
b) 1
c) 4
d) 3
View Answer
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.
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
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
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.
6. How can we define ‘undefined value’ in R language?
a) Inf
b) Sup
c) Und
d) NaN
View Answer
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
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
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
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
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 .
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Check Information Technology Books
- Check R Programming Books
- Practice Programming MCQs
- Apply for Programming Internship