250+ TOP MCQs on Textual Data Formats and Answers

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

1. Which of the following is used for reading in saved workspaces?
a) unserialize
b) load
c) get
d) set

Answer: b
Clarification: unserialize is used for reading single R objects in binary form. Load is used for reading in saved workspaces. Search by name for an object (get) or zero or more objects (mget).

2. Point out the wrong statement?
a) write.table is used for for writing tabular data to text files (i.e. CSV) or connections
b) writeLines is used for for writing character data line-by-line to a file or connection
c) dump is used for for dumping a textual representation of multiple R objects
d) all of the mentioned

Answer: d
Clarification: There are analogous functions for writing data to files.

3. ________ is used for outputting a textual representation of an R object.
a) dput
b) dump
c) dget
d) dset

Answer: a
Clarification: dump is used for dumping a textual representation of multiple R objects.

4. Which of the following argument denotes if the file has a header line?
a) header
b) sep
c) file
d) footer

Answer: a
Clarification: sep is a string indicating how the columns are separated.

5. Point out the correct statement?
a) unserialize is used for converting an R object into a binary format for outputting to a connection
b) save is used for saving an arbitrary number of R objects in binary format to a file
c) The read.data() function is one of the most commonly used functions for reading data
d) save is not used for saving an arbitrary

Answer: b
Clarification: read.table reads a file in table format and creates a data frame from it.

6. Which of the following statement would read file “foo.txt”?
a) data <- read.table(“foo.txt”)
b) read.data <- read.table(“foo.txt”)
c) data <- read.data(“foo.txt”)
d) data <- data(“foo.txt”)

Answer: a
Clarification: R will automatically skip lines that begin with a #.

7. Which of the following function is identical to read .table?
a) read.csv
b) read.data
c) read.tab
d) read.del

Answer: a
Clarification: The read.csv() function is identical to read.table except that some of the defaults are set differently (like the sep argument).

8. Which of the following code would read 100 rows?
a) initial <- read.table(“datatable.txt”, nrows = 100)
b) tabAll <- read.table(“datatable.txt”, colClasses = classes)
c) initial <- read.table(“datatable.txt”, nrows = 99)
d) initial <- read.table(“datatable.txt”, nrows = 101)

Answer: a
Clarification: You can use the Unix tool wc to calculate the number of lines in a file.

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

> y <- data.frame(a = 1, b = "a")
> dput(y)

a)

structure(list(a = 1, b = list(1L, .Label = "a", class = "factor")), .Names
= c("a",
"b"), row.names = c(NA, -1L), class = "data.frame")

b)

list(list(a = 1, b = list(1L, .Label = "a", class = "factor")), .Names
= c("a",
"b"), row.names = c(NA, -1L), class = "data.frame")

c)

structure(list(a = 1, b = structure(1L, .Label = "a", class = "factor")), .Names
= c("a",
"b"), row.names = c(NA, -1L), class = "data.frame")

d) Error

Answer: c
Clarification: dput() output is in the form of R code and that it preserves metadata like the class of the object, the row names, and the column names.

10. Which of the following is used for reading tabular data?

> y <- data.frame(a = 1, b = "a")
> dput(y, file = "y.R")
> new.y <- dget("y.R")
> new.y

a)

b)

c)

d)

View Answer

Answer: a
Clarification: Multiple objects can be deparsed at once using the dump function and read back in using source.

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.