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 list ?

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

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

### View Answer

Answer: a [Reason:] The [[ operator can also use named indices so that you don’t have to remember the exact ordering of every element of the list.

2. Point out the correct statement :
a) You can also use the \$ operator to extract elements by name
b) \$ operator can be used with computed indices
c) The [[ operator can only be used with literal names
d) All of the mentioned

### View Answer

Answer: a [Reason:] You don’t need the quotes when you use the \$ operator.

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

```> x <- list(foo = 1:4, bar = 0.6, baz = "hello")
> name <- "foo"
> x\$name```

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

### View Answer

Answer: b [Reason:] Element “name” doesn’t exist.

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

```> x <- list(foo = 1:4, bar = 0.6, baz = "hello")
> name <- "foo"
> x[[name]]```

a) 1 2 3 4
b) 0 1 2 3
c) 1 2 3 4 5
d) All of the mentioned

### View Answer

Answer: a [Reason:] One thing that differentiates the [[ operator from the \$ is that the [[ operator can be used with computed indices.

5. Point out the wrong statement :
a) \$ operator semantics are similar to that of [[
b) The [[ operator can take an integer sequence if you want to extract a nested element of a list
c) The \$ operator can be used to extract multiple elements from a list
d) All of the mentioned

### View Answer

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

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

```> x <- list(a = list(10, 12, 14), b = c(3.14, 2.81))
> x[[c(1, 3)]]```

a) 13
b) 14
c) 15
d) All of the mentioned

### View Answer

Answer: b [Reason:] The [[ operator can take an integer sequence if you want to extract a nested element of a list.

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

```> x <- list(aardvark = 1:5)
> x\$a```

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

### View Answer

Answer: a [Reason:] Partial matching of names is allowed with [[ and \$.

8. Which of the followin code extracts 1st element of the 2nd element ?

` > x <- list(a = list(10, 12, 14), b = c(3.14, 2.81))`

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

### View Answer

Answer: a [Reason:] [ operator always returns an object of the same class as the original.

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

```> x <- list(aardvark = 1:5)
> x[["a", exact = FALSE]]```

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

### View Answer

Answer: a [Reason:] This is often very useful during interactive work if the object you’re working with has very long element names.

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

```> x <- c(1, 2, NA, 4, NA, 5)
> bad <- is.na(x)
> print(bad)```

a) FALSE FALSE FALSE FALSE TRUE FALSE
b) FALSE TRUE TRUE FALSE TRUE FALSE
c) FALSE FALSE TRUE FALSE TRUE FALSE
d) None of the mentioned

### View Answer

Answer: c [Reason:] A common task in data analysis is removing missing values (NAs).

### 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 .woocommerce-message { background-color: #98C391 !important; }