This set of R Programming Interview Questions and Answers focuses on “Data Types – 2”
1. Which of the following statement is invalid?
a) x <- c(1+0i, 2+4i)
b) x <- c(TRUE, FALSE)
c) x <- c(T, F)
d) None of the mentioned
View Answer
Explanation: T and F are shorthand ways to specify TRUE and FALSE.
2. Point out the correct statement?
a) Use explicit TRUE and FALSE values when indicating logical values
b) rm command is used to remove objects in R
c) R operates on named data structures
d) All of the mentioned
View Answer
Explanation: A number occurring by itself in an expression is taken as a vector of length one.
3. What will be the output of the following R code?
> x <- 6 > class(x)
a) “integer”
b) “numeric”
c) “real”
d) “imaginary”
View Answer
Explanation: class is used to determine data type of the variable.
4. What will be the output of the following R code?
> x <- 0:6 > as.logical(x)
a) FALSE TRUE TRUE TRUE TRUE TRUE TRUE
b) “0” “1” “2” “3” “4” “5” “6”
c) 0 1 2 3 4 5 6
d) 6 5 5 3 2 1
View Answer
Explanation: Sometimes, R can’t figure out how to coerce an object and this can result in NAs being produced.
5. Point out the correct statement?
a) The usual operator, <-, can be thought of as a syntactic shortcut to expression operation
b) Assignment can also be made using the function assignment()
c) Vectors can be used in arithmetic expressions, in which case the operations are performed element by element
d) seq() is used to delete the numbers
View Answer
Explanation: Vectors occurring in the same expression need not all be of the same length.
6. Which of the following is invalid assignment?
a)
> c(10.4, 5.6, 3.1, 6.4, 21.7) -> x
b)
> assign("x", c(10.4, 5.6, 3.1, 6.4, 21.7))
c)
> x <- c(10.4, 5.6, 3.1, 6.4, 21.7)
d) None of the mentioned
View Answer
Explanation: Assignments can also be made in the other direction, using the obvious change in the assignment operator.
7. What will be the output of the following R code?
> sqrt(-17)
a) -4.02
b) 4.02
c) NaN
d) 3.67
View Answer
Explanation: These metadata can be very useful in that they help to describe the object.
8. Which of the following code constructs vector of length 11?
a)
> v <- 3*x + y + 1
b)
> v <- 3*x + y + 2
c)
> v <- 2*x + y + 1
d)
> v <- 2*x + y + 4
Explanation: The elementary arithmetic operators are the usual +, -, *, / and ^ for raising to a power.
9. _______ function returns a vector of the same size as x with the elements arranged in increasing order.
a) sort()
b) orderasc()
c) orderby()
d) sequence()
View Answer
Explanation: There are other more flexible sorting facilities available like order() or sort.list() which produce a permutation to do the sorting.
10. Which of the following is used for generating sequences?
a) seq()
b) sequence()
c) order()
d) orderasc()
View Answer
Explanation: R has a number of facilities for generating commonly used sequences of numbers.
Sanfoundry Global Education & Learning Series – R Programming Language.
Here’s the list of Best Books in R Programming Language.
- Practice Programming MCQs
- Check Information Technology Books
- Apply for Programming Internship
- Check R Programming Books