250+ TOP MCQs on Data Types and Answers

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

1. Find the following type of vector?

a) Numeric
b) Character
c) Integer
d) Logical

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

2. All columns in a matrix must have the same mode and the _________ length.
a) Different
b) Same
c) May be the same
d) May be different

Answer: b
Clarification: All columns in a matrix must have the same mode(numeric, character, etc) and also the same length. byrow=TRUE indicates that the matrix should be filled by rows. byrow=FALSE indicates that the matrix should be filled by columns (the default).

3. ___________ provides optional labels with the columns and rows.
a) Disnames
b) Dimnames
c) Denmes
d) Demnesd

Answer: b
Clarification: byrow=TRUE indicates that the matrix should be filled by rows. byrow=FALSE indicates that the matrix should be filled by columns (the default). dimnames provides optional labels with the columns and rows.

4. ________ are similar to matrices but can have more than two dimensions.
a) Functions
b) Packages
c) Arrays
d) Columns

Answer: c
Clarification: Arrays are similar to matrices which can have more than two dimensions. See help(array) for details. Factors are created using the factor() function. We can Identify elements of a list using the [[]] convention.

5. Which is more general than a matrix, in that different columns can have different modes?
a) Data types
b) Data frames
c) Data sets
d) Databases

Answer: c
Clarification: A data frame is more general than a matrix, in that different columns can have different modes (numeric, character, factor, etc). This is similar to SAS and SPSS datasets. There are many ways to identify the elements of a data frame.

6. An ordered collection of objects or components are called ________
a) Data frames
b) Datasets
c) Databases
d) Lists

Answer: d
Clarification: An ordered collection of objects are called lists. A list allows you to gather a variety of (possibly unrelated) objects under one name. We can Identify elements of a list using the [[]] convention.

7. The ________ stores the nominal values as a vector of integers in the range of 1 to unique values in the nominal variable.
a) Factor
b) Matrix
c) Lists
d) Functions

Answer: a
Clarification: The factor stores the nominal values as a vector of integers in the range [1… k] (where k is the no. of unique values of the nominal variable), and an internal vector of character strings (the original values) mapped to these integers.

8. An ordered factor is used to represent an __________
a) Ordinal variable
b) Simple variable
c) Coordinal variable
d) Biordinal variable

Answer: a
Clarification: An ordered factor is used to represent an ordinal variable. R will treat factors as nominal variables and also ordered factors as ordinal variables in statistical procedures and graphical analyses.

9. On what basis of a variable, OS allocates memory and decides what can be stored in the reserved memory?
a) Data bases
b) Data sets
c) Data types
d) Lists

Answer: c
Clarification: Based on the data type of a variable, the OS allocates the memory and decides what can be stored on the reserved memory. This means that when you create a variable you reserve some space in memory.

10. The data type of the R-object becomes the data type of the ________
a) Functions
b) Packages
c) Variables
d) Lists

Answer: c
Clarification: In R, the variables are not declared as some data type. The variables are assigned with R-Objects and the data type of the R-object will become the data type of the variable. There are many types of R-objects.

250+ TOP MCQs on Control Structures and Answers

R Programming Quiz focuses on “Control Structures”.

1. Which of the following code skips the first 20 iterations?
a)

for(i in 1:100) {
             if(i <= 20) {
                next
      }
}

b)

for(i in 1:100) {
           if(i <= 19) {
           next
       }
}

c)

for(i in 1:100) {
         if(i <= 21) {
         next
      }
}

d)

for(i in 1:10) {
         if(i <= 24) {
         next
      }
}

View Answer

Answer: a
Clarification: next is used to skip an iteration of a loop.

 

2. Point out the correct statement?
a) The only way to exit a repeat loop is to call break
b) Infinite loops should generally be avoided
c) Control structures like if, while, and for allow you to control the flow of an R program
d) All of the mentioned

Answer: d
Clarification: Control structures are primarily useful for writing programs; for command line interactive work.

3. _________ initiates an infinite loop right from the start.
a) never
b) repeat
c) break
d) set

Answer: b
Clarification: These are not commonly used in statistical or data analysis applications but they do have their uses.

4. Which of the following R code snippet stops loop after 20 iterations?
a)

for(i in 1:100) {
      print(i)
              if(i > 20) {
               break 
       } 
}

b)

for(i in 1:100) {
      print(i)
              if(i > 19) {
               break 
       } 
}

c)

for(i in 1:100) {
      print(i)
              if(i < 20) {
               break 
       } 
}

d)

for(i in 2:100) {
      print("i")
              if(i > 150) {
               break 
       } 
}

View Answer

Answer: a
Clarification: break is used to exit a loop immediately, regardless of what iteration the loop may be on.

 

5. Point out the wrong statement?
a) Statements cannot be grouped together using braces ‘{’ and ‘}’
b) Computation in R consists of sequentially evaluating statements
c) Single statements are evaluated when a new line is typed at the end of the syntactically complete statement
d) next is used to skip an iteration of a loop

Answer: a
Clarification: Blocks are not evaluated until a new line is entered after the closing brace.

6. _______ is used to skip an iteration of a loop.
a) next
b) skip
c) group
d) cancel

Answer: a
Clarification: No statement below next in the current loop is evaluated.

7. Which of the following R code can be used to avoid numeric problems such as taking the logarithm of a negative number?
a)

 if( any(x < 0) ) y <- log(1+x) else y <- log(x)

b)

 if( any(x <= 0) ) y <- log(1+x) else y <- log(x)

c)

 if( any(x >= 0) ) y <- log(1+x) else y <- log(x)

d)

 if( any(x >> 0) ) x >- log(1+x) else x <- log(x)

View Answer

Answer: b
Clarification: The else clause is optional. The statement if(any(x <= 0)) x <- x[x <= 0] is valid.

 

8. R has ________ statements that provide explicit looping.
a) 2
b) 3
c) 4
d) 5

Answer: b
Clarification: They are for, while and repeat.

9. The syntax of the repeat loop is _________
a) rep statement
b) repeat statement
c) repeat else
d) repeat while

Answer: b
Clarification: The repeat statement causes repeated evaluation of the body until a break is specifically requested.

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

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

a) 2.2903605 2.3271663 -0.7060073 1.3622045 -0.2892720
b) 5.5
c) NULL
d) Error

Answer: a
Clarification: Conditions are always evaluated from left to right.

250+ TOP MCQs on Debugging Tools and Answers

R Programming question bank focuses on “Debugging Tools”

1. __________ prints out the function call stack after an error occurs.
a) trace()
b) traceback()
c) back()
d) traback()

Answer: b
Clarification: traceback() does nothing if there’s no error. trace() Interactive tracing and debugging of calls to a function or method.

2. Point out the wrong statement?
a) The primary task of debugging any R code is correctly diagnosing what the problem is
b) R provides only two tools to help you with debugging your code
c) print statement can be used for debugging purpose
d) The traceback() function must be called immediately after an error occurs

Answer: b
Clarification: R provides a number of tools to help you with debugging your code.

3. Which of the following is primary tool for debugging?
a) debug()
b) trace()
c) browser()
d) traceback()

Answer: a
Clarification: Primary tools are mainly used for debugging R code.

4. ________ allows you to insert debugging code into a function a specific places
a) debug()
b) trace()
c) browser()
d) traceback()

Answer: b
Clarification: The function call stack is the sequence of functions that was called before the error occurred.

5. Point out the correct statement?
a) The traceback() function must be called immediately after an error occurs
b) The debugger calls the browser at the very low level of the function body
c) Every time you call the mod() function it will launch the interactive debugger
d) R provides only two tools to help you with debugging your code

Answer: a
Clarification: Once another function is called, you lose the traceback.

6. _______ allows you to modify the error behavior so that you can browse the function call stack
a) debug()
b) trace()
c) recover()
d) traceback()

Answer: c
Clarification: The recover() function can be used to modify the error behavior of R when an error occurs.

7. ______ suspends the execution of a function wherever it is called and puts the function in debug mode.
a) debug()
b) trace()
c) recover()
d) browser()

Answer: d
Clarification: The debug() function initiates an interactive debugger (also known as the “browser” in R) for a function.

8. debug() flags a function for ______ mode in R mode.
a) debug
b) run
c) compile
d) recover

Answer: b
Clarification: debug() allows you to step through execution of a function one line at a time.

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.