250+ TOP MCQs on Functions and Answers

R Programming Question Paper focuses on “Functions”.

1. ________ function can be used to add datasets in R provided with the columns in the datasets should be the same.
a) rbind()
b) bbind()
c) jbind()
d) hbind()

Answer: a
Clarification: rbind () function can be used add datasets in R language provided the columns in the datasets should be the same. R has a large number of in-built functions and also the user can create their own functions.

2. _________ variables are categorical variables which can hold either string or numeric values.
a) Factor
b) Simpler
c) Function
d) Package

Answer: a
Clarification: Factor variables are categorical variables that hold the string or numeric values. Factor variables are used in various types of graphics and particularly for statistical modelling where a correct number of degrees of freedom is assigned to them.

3. What is the memory limit in R for 64 bit system?
a) 8 TB
b) 9TB
c) 10TB
d) 16TB

Answer: a
Clarification: 8TB is the memory limit for 64-bit system memory and 3GB is the limit for 32-bit system memory. A solid understanding of R’s memory management will help you predict how much memory you’ll need for a given task.

4. What is the memory limit in R for 32 bit system?
a) 8 TB
b) 9TB
c) 10TB
d) 3GB

Answer: d
Clarification: 8TB is the memory limit for 64-bit system memory and 3GB is the limit for 32-bit system memory. A solid understanding of R’s memory management will help you predict how much memory you’ll need for a given task.

5. What are the data types in R on which binary operators can be applied?
a) Scalars
b) Matrices
c) Vectors
d) Scalars, Matrices and Vectors

Answer: d
Clarification: R has a large number of in-built functions and the user can create their own functions. In R, a function is an object. So the R interpreter is able to pass control to the function.

6. __________ function is used in applying a function each level of factors.
a) With()
b) By()
c) To()
d) Here()

Answer: b
Clarification: BY () function is used for applying a function each level of factors. R has a large number of in-built functions and also user can create their own functions. In R, a function is an object. So the R interpreter is able to pass control to the function.

7. How do you create log linear models in R language?
a) loglm()
b) logmn()
c) logfn()
d) loghy()

Answer: a
Clarification: loglm is fit log-linear models by iterative proportional scaling. This function provides a front-end of the standard function, loglin, to allow log-linear models to be specified and fitted in a manner similar to that of other fitting functions.

8. What will be the class of the vector if you concatenate a number and NA?
a) Number
b) Character
c) Integer
d) No class

Answer: a
Clarification: The class of the resulting vector if you concatenate a number and NA is a Number. Decimal values are also called numeric in R. It is the default computational data type in R language.

9. ____________ is one type of the simplest machine learning classification algorithms that is a subset of supervised learning based on lazy learning.
a) K-Nearest Neighbour
b) Naïve Bayes
c) Travelling Salesman
d) N-Queen

Answer: a
Clarification: K-Nearest Neighbour is one type of the simplest machine learning classification algorithms that is a subset of supervised learning based on lazy learning. In this algorithm the function is approximated and also computations are deferred until classification.

10. What will be the class of the vector if you concatenate a number and a character?
a) Number
b) Character
c) Integer
d) No class

Answer: b
Clarification: The class of the resulting vector if you concatenate a number and a character is Character class. Decimal values are called numeric in R. It is the default computational data type in R language.

250+ TOP MCQs on ggplot2 and Answers

R Programming Aptitude Test focuses on “ggplot2 ”.

1. _________ generate aesthetic mappings that describe how variables in the data.
a) aes_all
b) aes_auto
c) aes
d) aes_string

Answer: c
Clarification: aes generate aesthetic mappings that describe how variables in the data. aes_auto is used for automatic aesthetic mapping.

2. Point out the correct statement?
a) update_element update contents of a theme
b) Use theme_update_element to modify a small number of elements of the current theme or use theme_set to completely override it
c) theme_bw is theme with grey background and white gridlines
d) is.rel reports whether x is a theme object

Answer: a
Clarification: update_element function is deprecated. Use %+replace% or +.gg instead.

3. ______ generate aesthetic mappings from a string.
a) aes_all
b) aes_auto
c) aes_string
d) aes_position

Answer: c
Clarification: Aesthetic mappings describe how variables in the data are mapped to visual properties (aesthetics) of geoms.

4. Which of the following is a differentiation related aesthetic?
a) aes_position
b) aes_group_order
c) aes_linetype_size_shape
d) ggorder

Answer: c
Clarification: aes_position is position related aesthetics.

5. Point out the wrong statement?
a) is.rel reports whether x is a theme object
b) is.theme reports whether x is a theme object
c) opts build a theme (or partial theme) from theme elements
d) theme_bw is theme with grey background and white gridlines

Answer: a
Clarification: is.rel reports whether x is a real object.

6. ________ modify a ggplot or theme object by adding on new components.
a) +.gg
b) -.gg
c) /.gg
d) .gg

Answer: a
Clarification: This operator allows you to add objects to a ggplot or theme object.

7. __________ create a complete ggplot appropriate to a particular data type.
a) autoplot
b) is.ggplot
c) printplot
d) qplot_ggplot

Answer: a
Clarification: autoplot uses ggplot2 to draw a particular plot for an object of a particular class in a single command.

8. Which of the following creates a new ggplot plot from a data frame?
a) qplot_ggplot
b) ggplot.data.frame
c) ggfluctuation
d) ggmissplot

Answer: b
Clarification: Default list of aesthetic mappings are displayed.

9. Which of the following draws plot on current graphics device?
a) ggmissplot
b) printplot
c) print.ggplot
d) ggfluctuation

Answer: c
Clarification: print.ggplot is also known as plot.ggplot.

10. ________ is used for relative sizing of theme elements.
a) rel
b) size
c) relative
d) timrinterval

Answer: a
Clarification: The syntax for rel is rel(X) where x is a number representing the relative size.

250+ TOP MCQs on Linear Regression and Answers

R Programming Language Multiple Choice Questions on “Linear Regression ”.

1. Which of the following convert a matrix of phi coefficients to polychoric correlations?
a) poly()
b) qline()
c) phi2poly
d) multi.plot()

Answer: c
Clarification: In statistics, polychoric correlation is a technique for estimating the correlation between two theorized normally distributed continuous latent variables, from two observed ordinal variables.

2. Which of the following is used to plot multiple histograms?
a) multi.plot()
b) multi.hist
c) xyplot.multi()
d) poly()

Answer: b
Clarification: A histogram is a graphical representation of the distribution of numerical data.

3. Which of the following count the number of good cases when doing pairwise analysis?
a) count.pairwise
b) count() +
c) anova.para()
d) count.poly()

Answer: a
Clarification: Pairwise comparison generally is any process of comparing entities in pairs to judge which of each entity is preferred.

4. Which of the following gives the summary of values likes mean etc?
a) mean
b) sd
c) describe
d) lm

Answer: c
Clarification: Describe give means, sd, skew, n, and se.

5. The purpose of correct.cor is to correct _________ in values.
a) difference
b) reliability
c) error
d) similar

Answer: b
Clarification: Correlation matrix and a vector of reliabilities is given to correct reliability.

6. What plot(s) are used to view the linear regression?
a) Scatterplot
b) Box plot
c) Density plot
d) Scatterplot, Boxplot, Density plot

Answer: d
Clarification: Each plot has its own importance of highlighting a specific feature. Scatter plot is used to visualise the relationship between the variables, Box plot is used to spot the outliers which effect line of best fit.

7. Common Metrics which are used to select linear model are ____________
a)

    R-Squared	Lower the better
    F-Statistic	Higher the better

b)

    R-Squared	Lower the better
    F-Statistic	Lower the better

c)

    R-Squared	Higher the better
    F-Statistic	Higher the better

d)

    R-Squared	Higher the better
    F-Statistic	Lower the better

View Answer

Answer: c
Clarification: For choosing linear regression model it is always advised to have more R-squared and lower F-Statistic. It ensures the best fit for the given data.

 

8. In lm(response ~ terms), terms specification of the form “first*second” is same as __________
a) first+second
b) first:second
c) first+second+first:second
d) first:second+second:first

Answer: c
Clarification: A terms specification of the form “first + second” indicates all the terms in first together with all the terms in second with duplicates removed.

250+ TOP MCQs on R Programming Language Basics and Answers

R Programming Language Multiple Choice Questions on “Basics”.

1. What is output of getOption(“defaultPackages”) in R studio?
a) Installs a new package
b) Shows default packages in R
c) Error
d) Nothing will print

Answer: b
Clarification: There are base packages (which come with R automatically), and contributed packages. The base packages are maintained by a select group of volunteers, called R Core. In addition to the base packages, there are over ten thousand additional contributed packages written by individuals all over the world.

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

    x <- c(3, 7, NA, 4, 7)
    y <- c(5, NA, 1, 2, 2)
    x + y

a) Symbol
b) Missing Data
c) 5
d) 15.5

Answer: b
Clarification: Missing data are a persistent and prevalent problem in many statistical analyses, especially those associated with the social sciences. R reserves the special symbol NA to represent missing data. Ordinary arithmetic with NA value gives NA’s (addition, subtraction, etc.) and applying a function to a vector that has a NA in it will usually give a NA.

3. R language is a dialect of which of the following languages?
a) S
b) C
c) MATLAB
d) SAS

Answer: a
Clarification: The R language is a dialect of S which was designed in the 1980s. Since the early 90’s the life of the S language has gone down a rather winding path. The scoping rules for R are the main feature that makes it different from the original S language.

4. R language has superficial similarity with _________
a) C
b) Python
c) MATLAB
d) SAS

Answer: a
Clarification: The language syntax has a superficial similarity with C, but the semantics are of the FPL (functional programming language) variety with stronger affinities with Lisp and APL. There are many syntaxes in C, which are closely resembled with R.

5. What is the mode of ‘a’ in the following R code?

     a <- c(1,” a”, FALSE)

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

Answer: b
Clarification: All three elements can be expressed as a character. Both paste() and cat() will printout text to the console by combining multiple character vectors together. The original data are formatted as character strings so we convert them to R’s Date format for easier manipulation.

6. What is the length of b?

a) 4
b) 5
c) 6
d) 0

Answer: c
Clarification: Length of b [1] 2 3 4 5 6 7 is 6. We can also create an empty list of a prespecified length with the vector() function. Data frames are represented as a special type of list where every element of the list has to have the same length.

7. What is the mode of b in the following R code?

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

Answer: a
Clarification: All the elements in ‘b’ can be expressed in numeric. Both paste() and cat() will printout text to the console by combining multiple character vectors together. The original data are formatted as character strings so we convert them to R’s Data format for easier manipulation.

8. What are the typeof(x) and mode(x) in the following R syntax?

a) Numeric, Integer
b) Integer, Numeric
c) Integer, Integer
d) Numeric, Numeric

Answer: b
Clarification: Here typeof() tells about the data type. They are an important type of object in R and are used in a variety of statistical modelling applications. You can determine an object’s type with the typeof function.

9. How many atomic vector types does R have?
a) 5
b) 6
c) 8
d) 10

Answer: b
Clarification: R language has 6 atomic data types. They are logical, integer, real, complex, string (or character) and raw. There is also a class for “raw” objects, but they are not commonly used directly in data analysis.

10. What is the function to set row names for a data frame?
a) row.names()
b) colnames()
c) col.names()
d) column name cannot be set for a data frame

Answer: a
Clarification: row.names() is the function to set row names for a data frame. Data frames have a special attribute called row.names, which indicate information about each row of the data frame.

250+ TOP MCQs on Textual Data Formats and Answers

R Programming Language Multiple Choice Questions on “Textual Data Formats”.

1. Unlike writing out a table or CSV file, dump() and dput() preserve the ______ so that another user doesn’t have to specify the all over again.
a) metadata
b) backup data
c) attribute data
d) normal data

Answer: a
Clarification: The read.table() function is one of the most commonly used functions for reading data. The help file with read.table() is worth reading in its entirety if only because the function gets used a lot.

2. One way to pass data around is by de parsing the R object with _________
a) dput()
b) write()
c) read()
d) dget()

Answer: a
Clarification: dput is used for outputting a textual representation of an R object. The dump() and dput() functions are useful because the resulting textual format is editable, and in the case of corruption, potentially recoverable.

3. Main way to read the data back in (parsing it) using the function.
a) dput()
b) write()
c) read()
d) dget()

Answer: d
Clarification: One way to pass data around is by deparsing the R object with dput() and reading it back in (parsing it) using dget(). dget is used for reading in R code files (inverse of dput).

4. dput() output is in the form of ___________
a) R code
b) text file code
c) binary code
d) both binary and text

Answer: a
Clarification: dput is used for outputting a textual representation of an R object. The dump() and dput() functions are useful because the resulting textual format is editable, and in the case of corruption, potentially recoverable.

5. Multiple objects can be de parsed at once using the ______ function.
a) dput()
b) write()
c) dump()
d) dget()

Answer: a
Clarification: dput is used for outputting a textual representation of an R object. The dump() and dput() functions are useful because the resulting textual format is editable, and in the case of corruption, potentially recoverable.

6. Multiple objects can be de parsed at once and read back using function _____
a) source()
b) read()
c) dget()
d) dput()

Answer: a
Clarification: Martin Machler made an important contribution by making Ross and Robert use the GNU General Public License to make R free software. This was critical because this allowed for the source code for the entire R system to be accessible to anyone who wanted to tinker with it.

7. We can dump() R objects to a file by passing _____
a) character vector of their names
b) object name
c) arguments
d) file name

Answer: a
Clarification: Dump is used for dumping a textual representation of multiple R objects. Descriptive representation of an R object by using the dput() or dump() functions. The dump() and dput() functions are useful because the resulting textual format is editable, and in the case of corruption, potentially recoverable.

8. If we want to save individual R objects to a file, we use the _______ function.
a) save()
b) save.image()
c) serialize()
d) deserialize()

Answer: a
Clarification: Save is used for saving an arbitrary number of R objects with a binary format (possibly compressed) to a file. The output of dput() can also be saved directly to a file.

9. If you have a lot of objects that you want to save to a file, we use ________ function.
a) save()
b) save.image()
c) serialize()
d) deserialize()

Answer: b
Clarification: Save is used for saving an arbitrary number of R objects with a binary format (possibly compressed) to a file. The output of dput() can also be saved directly to a file. Save.Image can be used mostly in R.

10. .rda extension used when saving data with function __________
a) save()
b) save.image()
c) save and save.image functions
d) serialize()

Answer: c
Clarification: Save is used for saving an arbitrary number of R objects with a binary format (possibly compressed) to a file. The output of dput() can also be saved directly to a file. Save.Image can be used mostly in R.

11. .RData extension used when we save data using the functions ___________
a) save()
b) save.image()
c) save and save.image functions
d) serialize()

Answer: c
Clarification: Save is used for saving an arbitrary number of R objects with a binary format (possibly compressed) to a file. The output of dput() can also be saved directly to a file. Save.Image can be used mostly in R.

12. When you call serialize() on an R object, the output will be ____ coded in hexadecimal format.
a) raw vector
b) character vector
c) integer vector
d) binary vector

Answer: a
Clarification: When you call serialize() on an R object, the output will be raw vector coded in hexadecimal format. Serialize is used for converting an R object into a binary format for outputting to a connection.

13. The benefit of the _____ function is that it is the only way to perfectly repressed an R object in an exportable format, without losing precision or any metadata.
a) save()
b) save.image()
c) unserialize()
d) serialize()

Answer: d
Clarification: Unserialize is used for reading single R objects in the binary form. Serialize is used for converting an R object into a binary format for outputting to a connection (or file).

14. load() is used for _______
a) reading
b) loading
c) working
d) not exist

Answer: a
Clarification: Load is used for reading in saved workspaces. After installing the package it is important that you load it into your R session with the library() function. you can load the data into R using the readRDS() function.

15. readlines is used for ____________
a) working on data
b) reading files
c) reading lines in files
d) not exist

Answer: b
Clarification: ReadLines is used for reading lines of a text file. you can load the data into R using the readRDS() function. Text files can be read line by line using the readLines() function. This function is useful for reading text files that may be unstructured or contain non-standard data.

250+ TOP MCQs on Functions and Answers

R Programming Language Multiple Choice Questions on “Functions”.

1. R code can be tested using _________________ package.
a) Dplyr
b) Hadley’s testthat
c) SKLearn
d) KNN

Answer: b
Clarification: R code can be tested using Hadley’s testthat package. Testthat draws inspiration from the xUnit family of testing packages, as well as from many of the innovative ruby testing libraries.

2. If the programmers want the output to be a data frame or a vector, then ________ function is used.
a) Lapply
b) Sapply
c) Vapply
d) Zapply

Answer: a
Clarification: If the programmers want the output to be a data frame or a vector, then sapply function is used whereas if the programmer wants the output to be a list then lapply is used. vapply allows the programmer to specific the output type.

3. If a programmer wants the output to be a list then ___________ function is used.
a) Lapply
b) Sapply
c) Vapply
d) Zapply

Answer: b
Clarification: sapply() function does the same jobs as lapply() function but returns a vector. We can use a user built-in function into lapply() or sapply(). We create a function named avg to compute the average of the minimum and maximum of the vector.

4. _____________ function is preferred over sapply as vapply allows the programmer to specific the output type.
a) Lapply
b) Japply
c) Vapply
d) Zapply

Answer: c
Clarification: Vapply is similar to sapply, but has a pre-specified type of return value, so it can be safer (and sometimes faster) to use. simplify2array() is the utility called from sapply() when simplify is not false and is similarly called from mapply().

5. Which function is difficult to implement?
a) Lapply
b) Japply
c) Vapply
d) Zapply

Answer: c
Clarification: Vapply allows the programmer to specific the output type. The disadvantage of using vapply is that it is very difficult to be implemented and more verbose. vapply is similar to sapply, but has a pre-specified type of return value, so it can be safer to use.

6. Which function is more verbose?
a) Lapply
b) Japply
c) Vapply
d) Zapply

Answer: c
Clarification: If a programmer wants the output to be a list then lapply is used. vapply allows the programmer to specific the output type. The disadvantage of using vapply is that it is very difficult to be implemented and more verbose.

7. _____________ will produce a sequential vector c( (1,2,3,4,5,6,7,8,9)).
a) Seq(9)
b) Seq(10)
c) Seq(15)
d) Seq(12)

Answer: a
Clarification: Seq generates a sequence of a priori known pattern. Seq_along(6) will produce a vector with length 6 whereas seq(6) will produce a sequential vector from 1 to 6 c((1,2,3,4,5,6)).

8. __________ function is used for reading the .csv file in R language.
a) Write.csv()
b) Read.csv ()
c) Let.csv()
d) Table.csv()

Answer: b
Clarification: read.csv () function is used for reading the .csv file in R language. We will use the built in the read.csv() function call, which reads the data as the data frame, and assign the data frame to a variable.

9. The line of code in R language should begin with a ________________
a) Hash symbol
b) Alphabet
c) Number
d) Character

Answer: a
Clarification: The line of code in R language should begin with a hash symbol (#). R has a large number of in-built functions and also the user can create their own functions.

10. _______________ returns TRUE then X can be termed as a matrix data object.
a) is.”matrix(X”)
b) is.matrix(X)
c) is.notamatrix(X )
d) is.matrix(“X”)

Answer: b
Clarification: The function call is.matrix(X ) returns TRUE then X can be termed as a matrix data object. R has a large number of in-built functions and also the user can create their own functions.