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 is valid syntax for if else statement in R ?
a)

if(<condition>) {
          ## do something
}
else {
          ## do something else
}

b)

if(<condition>) {
          ## do something
}
elseif {
          ## do something else
}

c)

if(<condition>) {
          ## do something
}
else if {
          ## do something else
}

d) All of the mentioned

View Answer

Answer: a [Reason:] If you have an action you want to execute when the condition is false, then you need an else clause.

2. Point out the correct statement :
a) Blocks are evaluated until a new line is entered after the closing brace
b) Single statements are evaluated when a new line is typed at the start of the syntactically complete statement
c) The if/else statement conditionally evaluates two statements
d) All of the mentioned

View Answer

Answer: c [Reason:] The if/else statement returns, as its value, the value of the statement that was selected.

3. Which of the following syntax is correct for while loop ?
a) while ( statement1 ) statement2
b) while ( statement1 ) else statement2
c) while ( statement1 ) do statement2
d) All of the mentioned

View Answer

Answer: a [Reason:] The while statement is very similar to the repeat statement.

4. Which of the following code generate a uniform random number ?
a)

x <- runif(1, 0, 10)
if(x > 3) {
    y <- 10
} else {
    y <- 0
}

b)

x <- run(1, 0, 10)
if(x > 3) {
    y <- 10
} else {
    y <- 0
}

c)

x <- random(1, 0, 10)
if(x > 3) {
    y <- 10
} else {
    y <- 0
}

d) All of the mentioned

View Answer

Answer: a [Reason:] The value of y is set depending on whether x > 3 or not.

5. Point out the wrong statement :
a) for will execute a loop a fixed number of times
b) break will execute a loop while a condition is true
c) if and else tests a condition and acting on it
d) none of the mentioned

View Answer

Answer: b [Reason:] The if-else structure allows you to test a condition and act on it depending on whether it’s true or false.

6. _______ is used to break the execution of a loop.
a) next
b) skip
c) break
d) all of the mentioned

View Answer

Answer: c [Reason:] Control structures allow you to respond to inputs or to features of the data and execute different R expressions accordingly.

7. Which of the following code generate a sequence of integers from 1 to 10 ?
a)

> for(i in 1:9) {
    + print(i)
+ }
[1]

b)

> for(i in 0:9) {
    + print(i)
+ }
[1]

c)

> for(i in 1:10) {
    + print(i)
+ }
[1]

d) All of the mentioned

View Answer

Answer: c [Reason:] In R, for loops take an iterator variable and assign it successive values from a sequence or vector.

8. Which of the following statement can be used to explicitly control looping ?
a) if
b) while
c) break
d) all of the mentioned

View Answer

Answer: c [Reason:] The break statement causes an exit from the innermost loop that is currently being executed.

9. Which of the following should be preferred for evaluation from list of alternatives ?
a) subsett
b) eval
c) switch
d) none of the mentioned

View Answer

Answer: b [Reason:] eval(x[[condition]]) is the best way to select one for evaluation.

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

> x <- c("a", "b", "c", "d")
> for(i in 1:4) {
    + ## Print out each element of 'x'
    + print(x[i])
+ }

a)

[1] "a"
[1] "b"
[1] "c"
[1] "d"

b)

[1] "c"
[1] "b"
[1] "a"
[1] "d"

c)

[1] "d"
[1] "c"
[1] "b"
[1] "a"

d) All of the mentioned

View Answer

Answer: a [Reason:] The above code print out each element of ‘x’.

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; }