250+ TOP MCQs on Packages and Answers

R Programming Questions focuses on “Packages ”.

1. ______ is used to view all packages installed.
a) library()
b) search()
c) .libPaths()
d) stringr()

Answer: a
Clarification: Both require() and library() can load (strictly speaking, attach) an R package.

2. ______ is used to get library location in R.
a) library()
b) search()
c) .libPaths()
d) stringr()

Answer: c
Clarification: libPaths() can add new paths to set of library trees searched.

3. ________ is used to view packages currently loaded.
a) library()
b) search()
c) .libPaths()
d) stringr()

Answer: b
Clarification: This search will allow you to search the contents of the R functions, package vignettes, and task views.

4. ________ contains tools for Approximate Bayesian Computation (ABC).
a) str
b) abc
c) zyz
d) yxq

Answer: b
Clarification: The package implements several ABC algorithms for performing parameter estimation and model selection.

5. Which of the following package combine multi-dimensional arrays?
a) stringr
b) comb
c) abind
d) anlyz

Answer: c
Clarification: This is a generalization of cbind and rbind.

6. Which of the following contains functions for processing uniaxial minute-to-minute accelerometer data?
a) accelerometry
b) abc
c) accrued
d) comb

Answer: a
Clarification: This package contains a collection of functions that perform operations on time-series accelerometer data, such as identify non-wear time, flag minutes that are part of an activity about, and find the maximum 10-minute average count value.

7. __________ is used for selecting regression transformations.
a) gac()
b) gpl()
c) avas()
d) ggc()

Answer: c
Clarification: ace() and avas() both are used for selecting regression transformations.

8. Which of the following is an R package for the exploratory analysis of genetic and genomic data?
a) adeg
b) adegenet
c) anc
d) abc

Answer: b
Clarification: This package contains Classes and functions for genetic data analysis within the multivariate framework.

9. ______ specializes in functions for analytical Customer Relationship Management.
a) adagio
b) ada
c) aCRM
d) adeg

Answer: c
Clarification: Convenience functions for data preparation and modeling are often used in aCRM.

10._________ searches for significant clusters in genetic data.
a) BayesCount
b) BayesComm
c) bayesclust
d) Bayescolcount

Answer: c
Clarification: Bayesclust is an R package for testing and searching for significant clusters. BayesCount is used for power calculations and Bayesian analysis of count distributions and FECRT data using MCMC.

250+ TOP MCQs on History of R and Answers

R Programming Language Multiple Choice Questions on “History of R”.

1. _____ programming language is a dialect of S.
a) B
b) C
c) R
d) K

Answer: c
Clarification: S was initiated in 1976⁷ as an internal statistical analysis environment—originally implemented as Fortran libraries.

2. Point out the WRONG statement?
a) Early versions of the S language contain functions for statistical modeling
b) The book Programming with Data by John Chambers documents S version of the language
c) In 1993 Bell Labs gave StatSci (later Insightful Corp.) an exclusive license to develop and sell the S language
d) The book Programming with Data by IBM documents S version of the language

Answer: a
Clarification: Insightful sold its implementation of the S language under the product name S-PLUS.

3. In 2004, ________ purchased the S language from Lucent for $2 million.
a) Insightful
b) Amazon
c) IBM
d) TCS

Answer: a
Clarification: TIBCO is the current owner of the S language and is its exclusive developer.

4. In 1991, R was created by Ross Ihaka and Robert Gentleman in the Department of Statistics at the University of _________
a) John Hopkins
b) California
c) Harvard
d) Auckland

Answer: d
Clarification: In 1993 the first announcement of R was made to the public. Ross’s and Robert’s experience developing R is documented in a 1996 paper in the Journal of Computational and Graphical Statistics.

5. Point out the wrong statement?
a) R is a language for data analysis and graphics
b) K is language for statistical modelling and graphics
c) One key limitation of the S language was that it was only available in a commercial package, S-PLUS
d) C is a language for data and graphics

Answer: b
Clarification: In 1996, a public mailing list was created (the R-help and R-devel lists) and in 1997 the R Core Group was formed, containing some people associated with S and S-PLUS.

6. Finally, in _________ R version 1.0.0 was released to the public.
a) 2000
b) 2005
c) 2010
d) 2012

Answer: a
Clarification: Source code for the entire R system is accessible to anyone who wanted to tinker with it.

7. R is technically much closer to the Scheme language than it is to the original _____ language.
a) B
b) C
c) C++
d) S

Answer: d
Clarification: R’s semantics, while superficially similar to S, are quite different.

8. The R-help and _____ mailing lists have been highly active for over a decade now.
a) R-mail
b) R-devel
c) R-dev
d) R-del

Answer: b
Clarification: There is considerable activity on web sites like Stack Overflow as well.

9. Which of the following describes R language?
a) Free
b) Paid
c) Available for free trial only
d) Testing

Answer: a
Clarification: A major advantage that R has over many other statistical packages and is that it’s free.

10. The copyright for the primary source code for R is held by the ______ Foundation.
a) A
b) S
c) C
d) R

Answer: d
Clarification: It is published under the GNU General Public License version.

250+ TOP MCQs on Data Types and Answers

R Programming Language Multiple Choice Questions on “Data Types”.

1. Which function is used to combine the elements into a vector?
a) C()
b) D()
c) E()
d) F()

Answer: a
Clarification: When you want to create a vector with more than one element, you should use c() function which means to combine the elements into a vector. We can Identify elements of a list using the [[]] convention.

2. A __________ is an R-object which can contain many different types of elements inside it.
a) Vector
b) Lists
c) Matrix
d) Functions

Answer: b
Clarification: A list is an R-object which can contain many different types of elements in it like vectors, functions and even another list inside it. We can Identify elements of a list using the [[]] convention.

3. A _________ is a two-dimensional rectangular data set.
a) Vector
b) Lists
c) Matrix
d) Functions

Answer: c
Clarification: A matrix is a two-dimensional rectangular data set. It can be created using the vector input to a matrix function. The labels are always character irrespective of whether it is numeric or character and also Boolean etc in the vector.

4. Which function takes a dim attribute which creates the required number of dimensions?
a) Vector
b) Array
c) Matrix
d) Lists

Answer: b
Clarification: The array function takes a dim attribute which creates the required number of dimensions. While matrices are confined to two dimensions, arrays could be of any number of dimensions.

5. Factors are the r-objects which are created using a _________
a) Vector
b) Matrix
c) Lists
d) Array

Answer: a
Clarification: Factors are the r-objects which are created using a vector. It stores the vector with also the distinct values of the elements in the vector as labels. They are useful in statistical modelling.

6. Factors are created using the _______ function.
a) C()
b) Function()
c) Array()
d) Lists()

Answer: b
Clarification: Factors are created using the factor() function. The labels are always character irrespective of whether it is numeric or character or also Boolean etc. in the vector. The nlevels functions will give the count of levels.

7. By what function we can create data frames?
a) Data.frames()
b) Data.sets ()
c) Function ()
d) C ()

Answer: a
Clarification: Data frames are tabular data objects. Unlike a matrix in each data frame every column will contain different modes of data. Data Frames are created using the data.frame() function. It is the list of vectors of same length.

8. vectors can be one of two types namely atomic vectors and _______
a) Matrix
b) Vector
c) Lists
d) Array

Answer: c
Clarification: A vector is the most common and basic data structure in R. Technically, vectors can be one of two types of atomic vectors and lists. Although vector most commonly refers to the atomic types.

9. Lists can be coerced with which function?
a) As.lists
b) Has.lists
c) In.lists
d) Co.lists

Answer: a
Clarification: Lists are sometimes called generic vectors because the elements of a list can be of any type of R object, even lists containing further lists. This property makes them fundamentally different from other atomic vectors. Create lists using list() and coerce other objects using as.list().

10. A data frame is a special type of list where every element of the list has ______ length.
a) Same
b) Different
c) May be different
d) May be same

Answer: a
Clarification: A data frame is a very important data type in R. It’s pretty much the de facto data structure for most tabular data and what we use for statistics. A data frame was a special type of list in which every element of the list has the same length.

11. Data frames can have additional attributes such as __________
a) Rowname()
b) Rownames()
c) R.names()
d) D.names()

Answer: b
Clarification: Data frames can have additional attributes such as rownames(), which can be useful for annotating data, like subject_id or sample_id. But most of the time they are not used. A data frame is an important data type in R.

12. Decimal values are referred as ________ data types in R.
a) Numeric
b) Character
c) Integer
d) Lists

Answer: a
Clarification: Decimal values are referred to as numeric data types in R. Data frames are the tabular data objects. Unlike a matrix in data frame every column can contain different modes of data.

13. Which is the basic data structure of R containing the same type of data?
a) Functions
b) Array
c) Vector
d) Lists

Answer: c
Clarification: Vector is a basic data structure in R that contains an element of similar type. These data types in R can be logical, integer, double, character, complex and also raw. In R using the function, typeof() one can check the data type of vector.

14. In R using the function, ________ one can check the data type of vector.
a) Typeof()
b) Castof()
c) Function()
d) C()

Answer: a
Clarification: In R using the function, typeof() one can check the data type of vector. Vector is a basic data structure in R which contains element of similar type. These data types in R can be logical, integer, double, character, complex and also raw.

15. __________are Data frames which contain lists of homogeneous data in a tabular format.
a) Matrix
b) Vector
c) Lists
d) Array

Answer: c
Clarification: Matrices are Data frames which contain lists of homogeneous data in a tabular format. Technically, vectors can be one of two types of atomic vectors and lists. Although vector is mostly refers to the atomic types.

250+ TOP MCQs on Control Structures and Answers

R Programming MCQs focuses on “Control Structures”.

1. What will be the output of the following R code?

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

a) 5
b) 5.5
c) NULL
d) 58

Answer: b
Clarification: 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 semicolon 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

Answer: d
Clarification: Both semicolons and new lines can be used to separate statements.

3. What will be the output of the following R code?

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

a) 10
b) 1
c) NULL
d) 5

Answer: c
Clarification: If value is too large or too small NULL is returned.

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

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

a) “banana”
b) “Neither”
c) “broccoli”
d) Error

Answer: a
Clarification: 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) Computation in R consists of sequentially evaluating statements

Answer: b
Clarification: They are break and next.

6.What will be the output of the following R 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) gives mean with values depending on rcauchy values

Answer: d
Clarification: A common use of switch is to branch according to the character value of one of the arguments to a function. Generates a random point pattern, a simulated realisation of the Neyman-Scott process with Cauchy cluster kernel.

7. Which of the following R 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)

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

View Answer

Answer: a
Clarification: 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) five

Answer: b
Clarification: 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)

forif loop( name in vector )
statement1

View Answer

Answer: c
Clarification: 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 R 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)

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

View Answer

Answer: a
Clarification: 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.

250+ TOP MCQs on Simulation and Answers

R Programming Language Multiple Choice Questions on “Simulation”.

1. ________ generate random Normal variates with a given mean and standard deviation.
a) dnorm
b) rnorm
c) pnorm
d) rpois

Answer: b
Clarification: The “r” function is the one that actually simulates random numbers from that distribution.

2. Point out the correct statement?
a) R comes with a set of pseudo-random number generators
b) Random number generators cannot be used to model random inputs
c) Statistical procedure does not require random number generation
d) For each probability distribution there are typically three functions

Answer: a
Clarification: R allows you to simulate from well known probability distributions like the Normal, Poisson, and binomial.

3. ______ evaluate the cumulative distribution function for a Normal distribution.
a) dnorm
b) rnorm
c) pnorm
d) rpois

Answer: c
Clarification: p stands for cumulative distribution.

4. _______ generate random Poisson variates with a given rate.
a) dnorm
b) rnorm
c) pnorm
d) rpois

Answer: d
Clarification: q stands for quantile function (inverse cumulative distribution).

5. Point out the wrong statement?
a) For each probability distribution there are typically three functions
b) For each probability distribution there are typically four functions
c) r function is sufficient for simulating random numbers
d) R comes with a set of pseudo-random number generators

Answer: a
Clarification: There are typically four functions available that start with a “r”, “d”, “p”, and “q”.

6. Which of the following evaluate the Normal probability density (with a given mean/SD) at a point?
a) dnorm
b) rnorm
c) pnorm
d) rpois

Answer: a
Clarification: That point can be a vector of points.

7. _________ is the most common probability distribution to work with.
a) Gaussian
b) Parametric
c) Paradox
d) Simulation

Answer: a
Clarification: Working with the Normal distributions requires using four functions.

8. What will be the output of the following R code?

a)

[1] 0.01874617 -0.18425254 -1.37133055 -0.59916772 0.29454513
[6] 0.38979430 -1.20807618 -0.36367602 -1.62667268 -0.25647839

b)

[1] 22.20356 21.51156 19.52353 21.97489 21.48278 20.17869 18.09011
[8] 19.60970 21.85104 20.96596

c)

Min. 1st Qu. Median Mean 3rd Qu. Max.
18.09 19.75 21.22 20.74 21.77 22.20

d) Error

Answer: a
Clarification: Here we simulate standard Normal random numbers with mean 0 and standard deviation 1.

9. What will be the output of the following R code?

> x <- rnorm(10)
> summary(x)

a)

[1] 0.01874617 -0.18425254 -1.37133055 -0.59916772 0.29454513
[6] 0.38979430 -1.20807618 -0.36367602 -1.62667268 -0.25647839

b)

[1] 22.20356 21.51156 19.52353 21.97489 21.48278 20.17869 18.09011
[8] 19.60970 21.85104 20.96596

c)

Min. 1st Qu. Median Mean 3rd Qu. Max.
18.09 19.75 21.22 20.74 21.77 22.20

d) Error

Answer: c
Clarification: We can modify the default parameters to simulate numbers with mean 20 and standard deviation 2.

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

a) 0.9772499
b) 1.9772499
c) 0.6772499
d) 2.6772499

Answer: a
Clarification: If you wanted to know what was the probability of a random Normal variable of being less than 2, you could use the pnorm() function to do that calculation.

250+ TOP MCQs on Packages and Answers

R Programming Puzzles focuses on “Packages ”.

1. ______ Uses Grieg-Smith method on 2 dimensional spatial data.
a) G.S.
b) g.data
c) G1DBN
d) G2db

Answer: a
Clarification: The function returns a GriegSmith object which is a matrix with block sizes, sum of squares for each block size as well as mean sums of squares. G1DBN is a package performing Dynamic Bayesian Network Inference.

2. ______ finds K best paths in a given graph.
a) kBestShortestPaths
b) kcirt
c) ktrees
d) kmap

Answer: a
Clarification: This package provides some routines to conduct the K-adaptive partitioning (kaps) and recursive partitioning (lrtree) for survival data.

3. ________ is a package for parsing, applying, and manipulating data cleaning rules
a) edr
b) editrules
c) edrGraphicalTools
d) edrtools

Answer: b
Clarification: editrules is a package for parsing, applying, and manipulating data cleaning rules. edrGraphicalTools provides tools for dimension reduction methods.

4. ________ performs class prediction based on microarray data and clinical parameters
a) M3
b) M2
c) MAclinical
d) M5

Answer: b
Clarification: M3 is used for reading M3 files.

5. Which of the following package provide namespace management functions not yet present in base R?
a) stringr
b) namespace
c) nbpMatching
d) messagewarning

Answer: b
Clarification: The package namespace is one of the most confusing parts of building a package. nbpMatching contains functions for non-bipartite optimal matching.

6. Which of the following is used to analyze paleontological time-series?
a) accelerometry
b) parfossil
c) paleoTS
d) nbpMatching

Answer: c
Clarification: This package contains parfossil parallelized functions for palaeoecological and palaeogeographical analysis.

7. __________ is used for the analysis of air pollution data.
a) air
b) openair
c) opena
d) openara

Answer: b
Clarification: Data are typically hourly time series and both monitoring data and dispersion model output can be analysed.

8. Which of the following package contains functions for reading and displaying satellite data for oceanographic applications with R?
a) saves
b) satin
c) saws
d) termstrc

Answer: b
Clarification: Saves is used for faster loading of variables.

9. ______ is used for Visualisation, verification and calibration of ternary probabilistic forecasts.
a) toss
b) termstrc
c) ternvis
d) satin

Answer: c
Clarification: TESS is used for faster simulation of reconstructed phylogenetic trees under time-dependent birth-death processes.

10. _________ uniforms and customizes plots of packages ggplot2, graphics and lattice.
a) uniCox
b) uniPlot
c) unknownR
d) unigraph

Answer: b
Clarification: uniPlot() allows to change parameters of the packages graphics, lattice and ggplot2 and to make these changes persistent over one R session.