R Programming MCQ Questions And Answers - Data Types
This section focuses on "Data Types" in R Programming. These Multiple Choice Questions (MCQ) should be practiced to improve the R Programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. What will be output for the following code?
v <- TRUE
print(class(v))
A. logical
B. Numeric
C. Integer
D. Complex
View Answer
Ans : A
Explanation: It produces the following result :
[1] ""logical""
2. What will be output for the following code?
v <- ""TRUE""
print(class(v))
A. logical
B. Numeric
C. Integer
D. Character
View Answer
Ans : D
Explanation: It produces the following result :
[1] ""character""
3. In R programming, the very basic data types are the R-objects called?
A. Lists
B. Matrices
C. Vectors
D. Arrays
View Answer
Ans : C
Explanation: In R programming, the very basic data types are the R-objects called vectors
4. Data Frames are created using the?
A. frame() function
B. data.frame() function
C. data() function
D. frame.data() function
View Answer
Ans : B
Explanation: Data Frames are created using the data.frame() function
5. Which functions gives the count of levels?
A. level
B. levels
C. nlevels
D. nlevel
View Answer
Ans : C
Explanation: Factors are created using the factor() function. The nlevels functions gives the count of levels.
6. Point out the correct statement?
A. Empty vectors can be created with the vector() function
B. A sequence is represented as a vector but can contain objects of different classes
C. "raw” objects are commonly used directly in data analysis
D. The value NaN represents undefined value
View Answer
Ans : A
Explanation: A vector can only contain objects of the same class.
7. What will be the output of the following R code?
> x <- vector(""numeric"", length = 10)
> x
A. 1 0
B. 0 0 0 0 0 0 0 0 0 0
C. 0 1
D. 0 0 1 1 0 1 1 0
View Answer
Ans : B
Explanation: You can also use the vector() function to initialize vectors.
8. What will be output for the following code?
> sqrt(-17)
A. -4.02
B. 4.02
C. 3.67
D. NAN
View Answer
Ans : D
Explanation: These metadata can be very useful in that they help to describe the object.
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
Ans : A
Explanation: There are other more flexible sorting facilities available like order() or sort.list() which produce a permutation to do the sorting.
10. What will be the output of the following R code?
> m <- matrix(nrow = 2, ncol = 3)
> dim(m)
A. 3 3
B. 3 2
C. 2 3
D. 2 2
View Answer
Ans : C
Explanation: Matrices are constructed column-wise.
Discussion