R Programming Questions and Answers – Data Types – 2

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

Answer: d
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

Answer: d
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

Answer: b
Explanation: class is used to determine data type of the variable.

advertisement
advertisement

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

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
> 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

Answer: a
Explanation: Sometimes, R can’t figure out how to coerce an object and this can result in NAs being produced.

advertisement

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

Answer: c
Explanation: Vectors occurring in the same expression need not all be of the same length.

6. Which of the following is invalid assignment?
a)

advertisement
 > 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

Answer: d
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

Answer: c
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
View Answer
Answer: c
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

Answer: a
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

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

To practice all areas of R Programming for Interviews, 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.