Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

1. Which of the following extracts first element from the following vector ?

 > x <- c("a", "b", "c", "c", "d", "a")

a) x[10].
b) x[1].
c) x[0].
d) None of the mentioned

View Answer

Answer: b [Reason:] Vectors are basic objects in R and they can be subsetted using the [ operator.

2. Point out the correct statement :
a) There are three operators that can be used to extract subsets of R objects
b) The [ operator is used to extract elements of a list or data frame by literal name
c) The [[ operator is used to extract elements of a list or data frame by string name
d) All of the mentioned

View Answer

Answer: a [Reason:] Three operators are [,[[ and $.

3. Which of the following extracts first four element from the following vector ?

 > x <- c("a", "b", "c", "c", "d", "a")

a) x[0:4].
b) x[1:4].
c) x[0:3].
d) all of the mentioned

View Answer

Answer: b [Reason:] The [ operator can be used to extract multiple elements of a vector by passing the operator an integer sequence.

4. What would be the output of the following code ?

> x <- c("a", "b", "c", "c", "d", "a")
> x[c(1, 3, 4)]

a) “a” “b” “c”
b) “a” “c” “c”
c) “a” “c” “b”
d) All of the mentioned

View Answer

Answer: b [Reason:] The sequence does not have to be in order; you can specify any arbitrary integer vector.

5. Point out the wrong statement :
a) $ operator semantics are similar to that of [[
b) The [ operator always returns an object of the same class as the original
c) The $ operator is used to extract elements of a list or a data frame
d) All of the mentioned

View Answer

Answer: C [Reason:] The [[ operator is used to extract elements of a list or a data frame.It can only be used to extract a single element and the class of the returned object will not necessarily be a list or data frame.

6. What would be the output of the following code ?

> x <- matrix(1:6, 2, 3)
> x[1, 2]

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

View Answer

Answer: a [Reason:] Matrices can be subsetted in the usual way with (i,j) type indices.

7. What would be the output of the following code ?

> x <- matrix(1:6, 2, 3)
> x[1, ]

a) 1 3 5
b) 2 3 5
c) 3 3 5
d) file

View Answer

Answer: a [Reason:] Indices can also be missing.

8. Which of the followin code extracts the second column for the following matrix ?

 > x <- matrix(1:6, 2, 3)

a) x[2, ].
b) x[1, 2].
c) x[, 2].
d) all of the mentioned

View Answer

Answer: c [Reason:] This behavior is used to access entire rows or columns of a matrix.

9. What would be the output of the following code ?

> x <- matrix(1:6, 2, 3)
> x[1, , drop = FALSE]

a)

[,1] [,2] [,3]
[1,] 1 3 5

b)

[,1] [,2] [,3]
[1,] 2 3 5

c)

[,1] [,2] [,3]
[1,] 1 2 5

d) None of the mentioned

View Answer

Answer: a [Reason:] By default, when a single element of a matrix is retrieved, it is returned as a vector of length 1 rather than a $1times 1$ matrix.

10.What would be the output of the following code ?

> x <- list(foo = 1:4, bar = 0.6)
> x

a)

$foo
[1] 1 2 3 4
$bar
[1] 0.6

b)

$foo
[1] 0 1 2 3 4
$bar
[1] 0 0.6

c)

$foo
[1] 0 1 2 3 4
$bar
[1] 0.6

d) None of the mentioned

View Answer

Answer: a [Reason:] The [[ operator can be used to extract single elements from a list.

Synopsis and Project Report

You can buy synopsis and project from distpub.com. Just visit https://distpub.com/product-category/projects/ and buy your university/institute project from distpub.com