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. What will be the output of the following code ?

> x <- 3
> switch(2, 2+2, mean(1:10), rnorm(5))

a) 5
b) 5.5
c) NULL
d) All of the mentioned

View Answer

Answer: b [Reason:] If value is a number between 1 and the length of list then the corresponding element of list is evaluated and the result returned.

2. Point out the correct statement :
a) Statements, such as x<-1:10 or mean(y), can be separated by either a semi-colon or a new line
b) Whenever the evaluator is presented with a syntactically complete statement that statement is evaluated and the value returned
c) Computation in R consists of sequentially evaluating statements
d) All of the mentioned

View Answer

Answer: d [Reason:] Both semicolons and new lines can be used to separate statements.

3.Which will be the output of following code ?

> x <- 3
> switch(6, 2+2, mean(1:10), rnorm(5))

a) 10
b) 1
c) NULL
d) All of the mentioned

View Answer

Answer: c [Reason:] If value is too large or too small NULL is returned.

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

> y <- "fruit"
> switch(y, fruit = "banana", vegetable = "broccoli", "Neither")

a) “banana”
b) “Neither”
c) “broccoli”
d) all of the mentioned

View Answer

Answer: a [Reason:] If value is a character vector then the element of ‘…’ with a name that exactly matches value is evaluated.

5. Point out the correct statement :
a) The next statement causes an exit from the innermost loop that is currently being executed
b) There are two statements that can be used to explicitly control looping
c) The break statement immediately causes control to return to the start of the loop
d) None of the mentioned

View Answer

Answer: b [Reason:] They are break and next.

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

> centre <- function(x, type) {
+ switch(type,
+        mean = mean(x),
+        median = median(x),
+        trimmed = mean(x, trim = .1))
+ }
> x <- rcauchy(10)
> centre(x, "mean")

a) 0.8760325
b) 0.5360891
c) 0.6086504
d) All of the mentioned

View Answer

Answer: a [Reason:] A common use of switch is to branch according to the character value of one of the arguments to a function.

7. Which of the following code will print “Neither” ?
a)

> y <- "meat"
> switch(y, fruit = "banana", vegetable = "broccoli", "Neither")

b)

> y <- "brocolli"
> switch(y, fruit = "banana", vegetable = "broccoli", "Neither")

c)

> y <- "banana"
> switch(y, fruit = "banana", vegetable = "broccoli", "Neither")

d) All of the mentioned

View Answer

Answer: a [Reason:] If there is no match a single unnamed argument will be used as a default.

8. R has ________ basic indexing operators.
a) two
b) three
c) four
d) all of the mentioned

View Answer

Answer: b [Reason:] R contains several constructs which allow access to individual elements or subsets through indexing operations.

9. The syntax of the for loop is :
a)

for ( $name in vector )
statement1

b)

for loop( name in vector )
statement1

c)

for ( name in vector )
statement1

d) None of the mentioned

View Answer

Answer: c [Reason:] For each element in vector the variable name is set to the value of that element and statement1 is evaluated.

10. Which of the following code syntax is syntactically valid ?
a)

if ( statement1 ) {
    statement2
} else if ( statement3 ) {
    statement4
} else if ( statement5 ) {
    statement6
} else
    statement8

b)

if ( statement1 ) {
    statement2
} elseif ( statement3 ) {
    statement4
} elseif ( statement5 ) {
    statement6
} else
    statement8

c)

if ( statement1 ) {
    statement2
} elseif ( statement3 ) {
    statement4
} else if ( statement5 ) {
    statement6
} else
    statement8

d) All of the mentioned

View Answer

Answer: a [Reason:] If the optional else clause is omitted and all the odd numbered statements evaluate to FALSE no statement will be evaluated and NULL is returned.

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