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 apply function in R ?
a) apply()
b) tapply()
c) fapply()
d) all of the mentioned

View Answer

Answer: b [Reason:] Functions can be passed as arguments to other functions.

2. Point out the correct statement :
a) Writing functions is a core activity of an R programmer
b) Functions are often used to encapsulate a sequence of expressions that need to be executed numerous times
c) Functions are also often written when code must be shared with others or the public
d) All of the mentioned

View Answer

Answer: d [Reason:] It represents the key step of the transition from a mere “user” to a developer who creates new functionality for R.

3. Functions are defined using the _________ directive and are stored as R objects
a) function()
b) funct()
c) functions()
d) all of the mentioned

View Answer

Answer: a [Reason:] In particular, they are R objects of class “function”.

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

> f <- function() {
+             ## This is an empty function
+ }
> f()

a) 0
b) No result
c) NULL
d) All of the mentioned

View Answer

Answer: c [Reason:] This function takes no arguments and does nothing.

5. Point out the wrong statement :
a) Functions in R are “second class objects”
b) The writing of a function allows a developer to create an interface to the code, that is explicitly specified with a set of parameters
c) Functions provides an abstraction of the code to potential users
d) None of the mentioned

View Answer

Answer: a [Reason:] Functions in R are “first class objects”, which means that they can be treated much like any other R object.

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

> f <- function() {
+              ## This is an empty function
+ }
> class(f)

a) “function”
b) “class”
c) “procedure”
d) All of the mentioned

View Answer

Answer: a [Reason:] Functions have their own class.

7. Which of the following code will print “Hello, world!” ?
a)

> f <- function() {
+              cat("Hello, world!n")
+ }
> f()

b)

>  f <- function() {
+              cat("Hello, World!n")
+ }
> f()

c)

> f <- function() {
+             cat("Hello world!n")
+ }
> f()

d) All of the mentioned

View Answer

Answer: a [Reason:] This function has a non-trivial function body.

8. What will be the output of following code ?

> f <- function(num) {
+ for(i in seq_len(num)) {
+               cat("Hello, world!n")
+ }
+ }
> f(3)

a)

Hello, world!
Hello, world!

b)

Hello, world!
Hello, world!
Hello, world!

c)

Hello, world!

d) All of the mentioned

View Answer

Answer: b [Reason:] In general, if you find yourself doing a lot of cutting and pasting, that’s usually a good sign that you might need to write a function.

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

> f <- function(num) {
+ hello <- "Hello, world!n"
+ for(i in seq_len(num)) {
+                    cat(hello)
+ }
+                    chars <- nchar(hello) * num
+                    chars
+ }
> meaningoflife <- f(3)
> print(meaningoflife)

a) 32
b) 42
c) 52
d) All of the mentioned

View Answer

Answer: a [Reason:] This function returns the total number of characters printed to the console.

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