vSanfoundryMenu
R Programming Questions and Answers – Overview of R – 1
This set of R Programming Language Multiple Choice Questions & Answers
(MCQs) focuses on “Overview of R – 1”.
1. They primary R system is available from the ______
a) CRAN
b) CRWO
c) GNU
d) CRDO
View Answer
Answer: a
Explanation: CRAN stands for Comprehensive R Archive Network.
2. Point out the wrong statement?
a) Key feature of R was that its syntax is very similar to S
b) R runs only on Windows computing platform and operating system
c) R has been reported to be running on modern tablets, phones, PDAs, and
game consoles
d) R functionality is divided into a number of Packages
View Answer
Answer: b
Explanation: R runs on almost any standard computing platform and
operating system.
ADVERTISEMENT
3. R functionality is divided into a number of ________
a) Packages
b) Functions
c) Domains
d) Classes
View Answer
Answer: a
Explanation: CRAN also hosts many add-on packages that can be used to
extend the functionality of R.
4. Which Package contains most fundamental functions to run R?
a) root
b) child
c) base
d) parent
View Answer
Answer: c
Explanation: base package in R contains the most fundamental functions.
5. Point out the wrong statement?
a) One nice feature that R shares with many popular open source projects is
frequent releases
b) R has sophisticated graphics capabilities
c) S’s base graphics system allows for very fine control over essentially every
aspect of a plot or graph
d) All of the mentioned
View Answer
Answer: c
Explanation: R has maintained the original S philosophy, which is that it
provides a language that is both useful for interactive work, but contains a
powerful programming language for developing new tools.
6. Which of the following is a base package for R language?
a) util
b) lang
c) tools
d) spatial
View Answer
Answer: c
Explanation: The other packages contained in the “base” system include
utils, stats, datasets, graphics, grDevices, grid, methods, parallel, compiler,
splines, tcltk, stats4.
Note: Join free Sanfoundry classes at Telegram or Youtube
ADVERTISEMENT
7. Which of the following is “Recommended” package in R?
a) util
b) lang
c) stats
d) spatial
View Answer
Answer: d
Explanation: “Recommended” packages also include boot, class, cluster,
codetools, foreign, KernSmooth, lattice, mgcv, nlme, rpart, survival, MASS,
nnet, Matrix.
8. What is the output of getOption(“defaultPackages”) in R studio?
a) Installs a new package
b) Shows default packages in R
c) Error
d) Nothing will print
View Answer
Answer: b
Explanation: 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.
9. Advanced users can write ___ code to manipulate R objects directly.
a) C, C++
b) C++, Java
c) Java, C
d) Java
View Answer
Answer: a
Explanation: For computationally-intensive tasks, C, C++ and Fortran code
can be linked and called at run time.
10. Which of the following is used for Statistical analysis in R language?
a) RStudio
b) Studio
c) Heck
d) KStudio
View Answer
Answer: a
Explanation: RStudio is a web application framework for R.
1. What will be the output of the following R program?
ADVERTISEMENT
R<-0:10
R[2]
a) 0
b) 1
c) 2
d) 3
View Answer
Answer: b
Explanation: 1 is the output of the above code as indexing in R starts from 1.
The output can be viewed in the R console. R studio has both R terminal and
the R console. Each output format is Implemented as a function in R. You can
customize the output by passing arguments to the function as sub-values of
the output field.
2. Which of the following operator is used to create integer sequences?
a) :
b) ;
c) –
d) ~
View Answer
Answer: a
Explanation: “:” operator is used to create an integer sequence. The other
operators are used for other purposes. Integer sequence is the basic
operator used in R. The [ operator can be used to extract multiple elements
of a vector by passing the operator an integer sequence.
2. What will be the output of the following R program?
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects.
Participate Now!
ADVERTISEMENT
Y<-0:5
Vector(y)
Y[3]
a) Error in vector(y): invalid ‘mode’ argument
b) 1
c) 4
d) 3
View Answer
Answer: a
Explanation: y is already vector; second line is an invalid argument. The third
line will give us the output. When an R vector is printed you will notice that
an index for the vector is printed in square brackets
[] on the side.
4. In R language, a vector is defined that it can only contain objects of the
________
a) Same class
b) Different class
c) Similar class
d) Any class
View Answer
Answer: a
Explanation: A vector can only contain objects of the same class. A vector
cannot have contain objects of the different class. Same class objects are
used mostly. The most basic type of R object is a vector. Empty vectors can
be created with the vector() function.
5. A list is represented as a vector but can contain objects of ___________
a) Same class
b) Different class
c) Similar class
d) Any class
View Answer
Answer: b
Explanation: A list can contain objects of different class. But a vector can
only contain objects of the same class. A vector cannot have contain objects
of the different class. Same class objects are used mostly.
Advertisement
6. How can we define ‘undefined value’ in R language?
a) Inf
b) Sup
c) Und
d) NaN
View Answer
Answer: d
Explanation: NaN is used to define the “undefined” value in the R language.
Undefined values also have some value in R. Missing values are denoted by
NA or NaN for q undefined mathematical operations. A NaN value is also NA
but the converse is not true.
7. What is NaN called?
a) Not a Number
b) Not a Numeric
c) Number and Number
d) Number a Numeric
View Answer
Answer: a
Explanation: NaN is called Not a Number. It is the full form of NaN. Full forms
can be viewed in R studio by typing help. A NaN value is also NA but the
converse is not true. The value NaN represents an undefined value.
8. How can we define ‘infinity’ in R language?
a) Inf
b) Sup
c) Und
d) NaN
View Answer
Answer: a
Explanation: Inf is used to define “Infinity” in R. It is somewhat different from
other programming languages. There is also a special number of Inf which
represents infinity.
9. What will be the output of the following R code?
Y <- c(TRUE, 2)
a) [1] “TRUE” “2”
b) [1] “TRUE” 2
c) [1] “0” “2”
d) [1] 1 2
View Answer
Answer: d
Explanation: Here TRUE is taken as 1. Then it will give output as 1 and 2.
FALSE can be taken as 0. T and F are short-hand ways to specify TRUE and
FALSE.
10. What is the class defined by the following R code?
Y<-c(2,”t”)
a) Character
b) Numeric
c) Logical
d) Integer
View Answer
Answer: a
Explanation: Here 2 is changed into character. Since the y belongs to list. A
list contains only characters. Combining a numeric object with a character
object will create a character vector because numbers can usually be easily
represented as strings
Is set of R Programming Language Multiple Choice Questions & Answers
(MCQs) focuses on “Overview of R – 3”.
1. What is the class defined in the following R code?
ADVERTISEMENT
Y<-c(FALSE,2)
a) Character
b) Numeric
c) Logical
d) Integer
View Answer
Answer: b
Explanation: Numeric and FALSE is executed as 0. It is somewhat different
from other programming languages. Console will give a class as Numeric. A
vector can only contain objects of the same class. A list Is represented as a
vector but can contain objects of different classes.
2. Which one of the following is not a basic datatype?
a) Numeric
b) Character
c) Data frame
d) Integer
View Answer
Answer: c
Explanation: Data frame is not the basic data type of R. Numeric, character,
integer are the basic types of R. The basic data types are used many times.
Data frames are used to store tabular data in R. They are an important type
of object in R and are used in a variety of statistical modelling applications.
3. How do you create an integer suppose 5 in R?
a) 5L
b) 5l
c) 5i
d) 5d
View Answer
Answer: a
Explanation: To create an integer L should be added to the integer. L is added
to specify that it is an integer. An integer can also be created with many
types. If you explicitly want an integer, you need to specify the L suffix.
Subscribe Now: R Programming Newsletter | Important Subjects Newsletters
ADVERTISEMENT
3. What will be the output of the following R code?
X<- c (“a”,” b”)
[Link](x)
a) [1] 1 2
b) [1] TRUE TRUE
c) [1] NA NA (Warning message: NAs introduced by coercion)
d) [1] NAN
View Answer
Answer: c
Explanation: Characters cannot be expressed as numeric. Therefore NA’s are
printed as output. NA will specify the missing elements in the list. When
nonsensical coercion takes place, you will usually get a warning from R.
5. The dimension attribute is itself an integer vector of length _______
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: b
Explanation: It is itself an integer vector of length 2. The dimension attribute
in R is an integer vector. Real values larger in modulus than the largest
integer are coerced to NA. Matrices are vectors with a dimension attribute.
The dimension attribute is itself an integer vector of length 2 (number of
rows, number of columns).
Advertisement
6. How could be the matrix constructed by using the following R code?
M <- matrix(1:6, nrow = 2, ncol = 3)
a) row-wise
b) column-wise
c) any manner
d) data insufficient
View Answer
Answer: b
Explanation: If nothing is mentioned, matrix is created column-wise. If we
want in row-wise then we have to specify. We have to mention “by row” to
create a matrix in row wise. The filter( ) function is used to extract subsets of
rows from a data frame. This function is similar to the existing subset( )
function.
7. Matrices can be created by row-binding with the help of the following
function.
a) rjoin()
b) rbind()
c) rowbind()
d) rbinding()
View Answer
Answer: b
Explanation: rbind() is used to create a matrix by row-binding. Row- binding
is the basic function of R. R – bind is used to bind the functions in R. Matrices
can be created by column-binding or row-binding with the cbind() and rbind()
functions.
8. What is the function used to test objects (returns a logical operator) if they
are NA?
a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()
View Answer
Answer: a
Explanation: [Link]() is the function used to test if they are NA. We can check
NA ‘s at any stage of the code. Generally, We will remove the NA’s for the
operations in R like mean etc.., [Link]() is used to test objects if they are NA.
9. What is the function used to test objects (returns a logical operator) if they
are NaN?
a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()
View Answer
Answer: d
Explanation: [Link]() is used to test if they are NaN. We can check NAN‘s at
any stage of the code. We will remove the NA’s for the operations in R.
[Link]() is used to test for NaN.
10. What is the function to set column names for a matrix?
a) names()
b) colnames()
c) [Link]()
d) column name cannot be set for a matrix
View Answer
Answer: b
Explanation: colnames() is the function to set column names for a matrix.
Rownames() is the function to set row names for a matrix. But we can’t use
both at a time. Column names and row names can be set separately using
the colnames() and rownames() functions.
This set of R Programming Language Multiple Choice Questions & Answers
(MCQs) focuses on “Basics – 1”.
1. The most convenient way to use R is at a graphics workstation running a
________ system.
a) windowing
b) running
c) interfacing
d) matrix
View Answer
Answer: a
Explanation: Most classical statistics and much of the latest methodology is
available for use with R.
2. Point out the wrong statement?
a) Setting up a workstation to take full advantage of the customizable
features of R is a straightforward thing
b) q() is used to quit the R program
c) R has an inbuilt help facility similar to the man facility of UNIX
d) Windows versions of R have other optional help systems also
View Answer
Answer: b
Explanation: help command is used for knowing details of particular
command in R.
ADVERTISEMENT
3. Which of the following is default prompt for UNIX environment?
a) >
b) >>
c) <
d) <<
View Answer
Answer: a
Explanation: When you use the R program it issues a prompt when it expects
input commands.
4. Which of the following will start the R program?
a) $ R
b) > R
c) * R
d) @ R
View Answer
Answer: a
Explanation: At this point R commands may be issued.
5. Point out the wrong statement?
a) Windows versions of R have other optional help system also
b) The [Link] command (alternatively ??) allows searching for help in
various ways
c) R is case insensitive as are most UNIX based packages, so A and a are
different symbols and would refer to different variables
d) $ R is used to start the R program
View Answer
Answer: c
Explanation: R is an expression language with a very simple syntax.
6. Which of the following statement is alternative to _________
Note: Join free Sanfoundry classes at Telegram or Youtube
ADVERTISEMENT
?solve
a) help(solve)
b) print(solve)
c) bind(solve)
d) matrix(solve)
View Answer
Answer: a
Explanation: help is used to get more information on any specific named
function.
7. Elementary commands in R consist of either _______ or assignments.
a) utilstats
b) language
c) expressions
d) packages
View Answer
Answer: c
Explanation: If an expression is given as a command, it is evaluated, printed
(unless specifically made invisible), and the value is lost.
8. If a command is not complete at the end of a line, R will give a different
prompt, by default it is ____________
A) *
b) –
c) +
d) /
View Answer
Answer: c
Explanation: Comments can be put almost anywhere, starting with a
hashmark (‘#’), everything to the end of the line is a comment.
9. Command lines entered at the console are limited to about ________ bytes.
a) 3000
b) 4095
c) 5000
d) 6000
View Answer
Answer: b
Explanation: Elementary commands can be grouped together into one
compound expression by braces (‘{’ and ‘}’).
Advertisement
10._____ text editor provides more general support mechanisms via ESS for
working interactively with R.
a) EAC
b) Emacs
c) Shell
d) ECAP
View Answer
Answer: b
Explanation: The recall and editing capabilities under UNIX are highly
customizable
s set of R Programming Language Multiple Choice Questions & Answers (MCQs)
focuses on “Basics – 2”.
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
View Answer
Answer: b
Explanation: 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.
ADVERTISEMENT
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
View Answer
Answer: b
Explanation: 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
View Answer
Answer: a
Explanation: 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.
Note: Join free Sanfoundry classes at Telegram or Youtube
ADVERTISEMENT
4. R language has superficial similarity with _________
a) C
b) Python
c) MATLAB
d) SAS
View Answer
Answer: a
Explanation: 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
View Answer
Answer: b
Explanation: 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.
advertisement
6. What is the length of b?
b <- 2:7
a) 4
b) 5
c) 6
d) 0
View Answer
Answer: c
Explanation: 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?
b <- c(TRUE, TRUE, 1)
a) Numeric
b) Character
c) Integer
d) Logical
View Answer
Answer: a
Explanation: 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?
x<-1:3
a) Numeric, Integer
b) Integer, Numeric
c) Integer, Integer
d) Numeric, Numeric
View Answer
Answer: b
Explanation: 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
View Answer
Answer: b
Explanation: 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) [Link]()
b) colnames()
c) [Link]()
d) column name cannot be set for a data frame
View Answer
Answer: a
Explanation: [Link]() is the function to set row names for a data frame.
Data frames have a special attribute called [Link], which indicate
information about each row of the data frame.
Set of R Programming Language Multiple Choice Questions & Answers (MCQs)
focuses on “Basics – 3”.
1. A single element of a character vector is referred as ________
a) Character string
b) String
c) Data strings
d) Raw data
View Answer
Answer: a
Explanation: Single element of a character vector is often referred to as a
character string. Dates are represented by the Date class and can be coerced
from a character string using the [Link]() function. This is a common way to
end up with a Date object in R.
ADVERTISEMENT
2. R files has an extension ______
a) .R
b) .S
c) .Rp
d) .c
View Answer
Answer: a
Explanation: All R files have an extension .R. R provides a mechanism for
recalling and re-executing previous commands. All S programmed files will have
an extension .S. But R has many functions than S.
3. If the code is stored in the external file, which of the following function is used
to call them to a working directory?
A) exec()
b) source()
c) execute()
d) sourcefile()
View Answer
Answer: b
Explanation: source is available in the file menu. Today R runs on almost any
standard computing platform and operating system. Its open source nature. The
copyright for the primary source code for R is held by the R Foundation and is
published under the GNU General Public License version.
4. Advanced programmers can write ______ code to manipulate R objects.
a) Python
b) Java
c) C
d) Java Script
View Answer
Answer: c
Explanation: C, C++ and Fortran can be linked. There are a number of people
had used something like C/C++ programming languages to manipulate the R
objects.
5. In ________ Insightful purchased the S language from Lucent for $2 million.
a) 2002
b) 2003
c) 2004
d) 2005
View Answer
Answer: c
Explanation: TIBCO is the current owner of the S language. In 2008, Insightful
was acquired by TIBCO for $25 million. As of this writing, TIBCO is the current
owner of the S language and is its exclusive developer.
Note: Join free Sanfoundry classes at Telegram or Youtube
ADVERTISEMENT
6. Functionality of R is divided into a number of __________
a) Functions
b) Domains
c) Packages
d) Files
View Answer
Answer: a
Explanation: CRAN hosts many add-on packages that can extend the
functionality of R. Connections allow R functions to talk to all different external
objects without having to write custom code for each object.
7. Dataframes can be converted into a matrix by calling the following function
data ______
a) matr()
b) matrix()
c) matrixf()
d) matrixfunc()
View Answer
Answer: b
Explanation: [Link] function should be used to coerce a data frame to a
matrix. It might seem that the [Link]() function should be used to coerce a
data frame to a matrix.
8. What will be the output of the following R code?
X <- (“a”, “b”)
[Link](x)
a) a b
b) “a” “b”
c) 1 1
d) Error
View Answer
Answer: d
Explanation: It is not possible to coerce, so you will get a Warning. Logical
creates a logical vector of the specified length. Each element of the vector is
equal to FALSE. [Link] attempts to coerce its argument to be of a logical
type.
Advertisement
9. What will be the output of the following R code?
A <- (“a” , “b”)
Mode(a)
a) Character
b) Numeric
c) Complex
d) Integer
View Answer
Answer: a
Explanation: Mode of the given command is a character. There are a
complementary function writeLines() that takes a character vector and writes
each element of the vector one line at a time to a text file.
10. Which of the following is not an object of R?
a) calls
b) expressions
c) strings
d) names
View Answer
Answer: c
Explanation: Calls, expressions and names are the three types of objects that
constitute the R language. There is really only one rule about vectors in R, which
is that A vector can only contain objects of the same class. R objects can have
names, which is very useful for writing readable code and self-describing
objects.
This set of R Programming Language Multiple Choice Questions & Answers
(MCQs) focuses on “Basics – 4”.
1. Is It possible to inspect the source code of R?
a) Yes
b) No
c) Can’t say
d) Some times
View Answer
Answer: a
Explanation: Anybody is free to download and install these packages and even
inspect the source code. The instructions for obtaining R largely depend on the
user’s hardware and operating system.
ADVERTISEMENT
2. How to install for a package and all of the other packages on which for
depends?
a) [Link] (for, depends = TRUE)
b) [Link] (“for”, depends = TRUE)
c) [Link] (“for”, depends = TRUE)
d) install (“for”, depends = FALSE)
View Answer
Answer: c
Explanation: To install a package named for, open up R and type
[Link](“for”). To install foo and additionally install all of the other
packages on which for depends, instead type [Link] (“for”, depends =
TRUE).
3. __________ function is used to watch for all available packages in library.
a) lib()
b) [Link]()
c) libr()
d) library()
View Answer
Answer: d
Explanation: Type library() at the command prompt to see a list of all available
packages in the library. For total information about the installation of R and add-
on packages, see the R Installation and Administration manual.
4. The longer programs are called ____________
a) Files
b) Structures
c) Scripts
d) Data
View Answer
Answer: c
Explanation: The longer programs called scripts, there is too much code to write
all at once at the command prompt. Furthermore, for longer scripts, it is
convenient to be able to only modify a certain piece of the script and run it
again in R.
5. Scripts will run on ___________________
a) Script Editors
b) Console
c) Terminal
d) GCC Compiler
View Answer
Answer: a
Explanation: script editors are designed to aid the communication and code
writing process. They have all sorts of features including R syntax highlighting,
automatic code completion, delimiter matching, and dynamic help on the R
functions.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects.
Participate Now!
ADVERTISEMENT
6. Which of the following is a “Recommended” package in R?
a) Util
b) Lang
c) Stats
d) Spatial
View Answer
Answer: d
Explanation: “Recommended” packages also include boot, class, cluster,
codetools, foreign, KernSmooth, lattice, mgcv, nlme, rpart, survival, MASS, nnet,
Matrix. There are about ten thousand packages in R now.
7. Full Form of GUI is ___________________
a) Guided User Interface
b) Graphical User Interface
c) Guided Used Interface
d) Graphical User Interval
View Answer
Answer: b
Explanation: GUI elements are usually accessed through a device. All programs
running a GUI use a consistent set of graphical elements so that once the user
learns a particular interface.
8. ____________ provides a point-and-click interface to many basic statistic
problems.
a) Commander
b) GUI
c) Console
d) Terminal
View Answer
Answer: a
Explanation: R Commander provides a point-and-click interface to statistical
problems. It is called the “Commander” because every time one makes a
selection, the code corresponding to the task is listed in the output window.
9. What will be the output of the following R code?
advertisement
options(digits = 16)
20/6
a) 3.33
b) 3.333
c) 3.3333333
d) 3.3333333333333333
View Answer
Answer: d
Explanation: We know that 20/6 is a repeating decimal, We can change the
number of digits displayed with options. This will make the number after the
decimal point to extend for the required amount.
10. In which IDE we can interact with R?
a) R studio
b) Console
c) GCC
d) Power shell
View Answer
Answer: a
Explanation: An IDE tailored to the needs of interactive data analysis and
statistical programming called R studio. In R studio we can directly interact with
R through the inbuilt functions and packages. We can also download new
packages.
11. Which programming language is more based on the results?
a) R
b) C
c) C++
d) Java
View Answer
Answer: a
Explanation: Compared to other programming languages, the R community
tends to be more focussed on results instead of processes. Knowledge of
software engineering best practice.
12. Why learning R becomes tough?
a) Special files
b) Functions
c) Packages
d) Special Cases
View Answer
Answer: d
Explanation: You are confronted with over 20 years of evolution every time you
use R. Learning R can be hard because there are many special cases in R to
remember. R is the best user of memory.
13. R is mostly used in ______________
a) Problem solving
b) Statistics
c) Probability
d) All of the mentioned
View Answer
Answer: d
Explanation: Statistics for relatively advanced users. R has thousands of
packages, designed, maintained, and widely used by statisticians. We can code
ourselves if a command is not present.
14. Why is it needed for R studio to update regularly?
a) Bugs
b) More Functions
c) Methods
d) For more packages
View Answer
Answer: a
Explanation: RStudio is very popular with a nice interface and well thought out,
especially for more advanced usage. It can be a bit buggy, so make sure you
update it regularly. Available on all platforms.
15. What is the meaning of “<-“?
a) Functions
b) Loops
c) Addition
d) Assignment
View Answer
Answer: d
Explanation: The expression a <- 16 creates a variable called a and gives it the
value 16 called assignment. The variable on the left is assigned to the value on
the right. The left side should have only a single one.
16. In the expression x <- 4 in R, what is the class of ‘x’ as determined by the
`class()’ function?
a) Character
b) Numeric
c) Integer
d) Word
View Answer
Answer: b
Explanation: In R, when you assign the value 4 to a variable ‘x’, its class is
“numeric”. The class() function confirms this by showing that the variable ‘x’
belongs to the “numeric” class
S set of R Programming Language Multiple Choice Questions & Answers (MCQs)
focuses on “Install and Configure”.
1. Which language is best for the statistical environment?
a) C
b) R
c) Java
d) Python
View Answer
Answer: b
Explanation: R is a popular programming language and environment for
statistical computing, graphics and also predictive analysis. Dundas BI
integrates with an existing R system at the data cube level via many transforms
which you can use to perform data generation or data processing.
ADVERTISEMENT
2. In order to use the R-related functionality in Dundas BI, you must have access
to an existing _________
A) Console
b) Terminal
c) Packages
d) R server
View Answer
Answer: d
Explanation: In order to use the R-related functionality in Dundas BI, we must
have access to an existing R server. There are configuration settings in Dundas
BI that allow administrators to specify the details for connecting to the external
R server.
3. The open source _________ software is available for Unix, Linux, and Windows
platforms.
a) Rserve
b) BServe
c) CServe
d) Dserve
View Answer
Answer: a
Explanation: The open source Rserve (Binary R Server) software is available for
Unix, Linux, and Windows platforms. However, due to limitations with the
Windows version, it is not recommended for use outside of evaluation purposes.
4. Modification in Dundas BI is done ______________
a) Directly
b) Indirectly
c) Need access to Server
d) Not known
View Answer
Answer: a
Explanation: We can view or modify configuration settings in Dundas BI through
an administration screen, so there’s no need to access the Dundas BI server
directly.
5. R has many functions regarding ________________
a) Statistics, Biotechnology
b) Probability, Microbiology
c) Distributions, Physics
d) Statistics, Probability, Distributions
View Answer
Answer: d
Explanation: R has many functions for all types of mathematical objects. For
example, Statistics, Probability, Distributions like Multivariate, Continuous,
Simple, Discrete etc.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate
Now!
ADVERTISEMENT
6. ___________ hosts many add-on packages that can be used to extend the
functionality of R.
a) CRAN
b) GNU
c) R studio
d) 450
View Answer
Answer: a
Explanation: The primary R system is available from the Comprehensive R
Archive Network, also known as CRAN. CRAN also hosts many add-on packages
that can be used to extend the functionality of R.
7. Which function is used to automatically vectorize?
a) lapply()
b) kapply()
c) mapply()
d) happly()
View Answer
Answer: c
Explanation: The mapply() function can be used to automatically “vectorize” a
function. What this means is that it can be used to take a function that typically
only takes single arguments and create a new function that can take vector
arguments.
8. Which is simpler for statistical programming?
a) C
b) Java
c) R
d) No language
View Answer
Answer: c
Explanation: R ([Link]) is a commonly used free Statistics software. R
allows you to carry out statistical analyses in an interactive mode, as well as
allowing simple programming.
9. A _______________ is a variable that holds one value at a time.
a) Scalar variable
b) Duplex
c) High
d) Vector
View Answer
Answer: a
Explanation: A scalar variable was a variable which holds one value at a time. It
is a single component which assumes a range of number or string values. A
scalar value Is associated with every point in space.
is set of R Programming Language Multiple Choice Questions & Answers (MCQs)
focuses on “Console Input and Evaluation – 1”.
1. What will be the output of the following R code?
> x <- 1
> print(x)
a) 1
b) 2
c) 3
d) 5
View Answer
Answer: a
Explanation: When a complete expression is entered at the prompt, it is
evaluated and the result of the evaluated expression is returned.
ADVERTISEMENT
2. Point out the wrong statement?
a) The grammar of the language determines whether an expression is complete
or not
b) The <- symbol is the assignment operator in R
c) The ## character indicates a comment
d) R does not support multi-line comments or comment blocks
View Answer
Answer: c
Explanation: Unlike some other languages, R does not support multi-line
comments or comment blocks.
3. Which of the R following code is example of explicit printing?
a)
> x <- 5
> x
b)
Note: Join free Sanfoundry classes at Telegram or Youtube
ADVERTISEMENT
> x <- 5
> print(x)
c)
> x <- "auto"
> x
d)
advertisement
> x <- "auto"
> x <- "auto"
View Answer
Answer: b
Explanation: Print command is used for outputting the value.
4. Files containing R scripts ends with extension ____________
a) .S
b) .R
c) .Rp
d) .SP
View Answer
Answer: b
Explanation: Under many versions of UNIX and on Windows, R provides a
mechanism for recalling and re-executing previous commands.
5. Point out the wrong statement?
a) : operator is used to create integer sequences
b) The numbers in the square brackets are part of the vector itself
c) There is a difference between the actual R object and the manner in which
that R object is printed to the console
d) Files containing R scripts ends with extension .R
View Answer
Answer: b
Explanation: They are merely part of the printed output.
6. If commands are stored in an external file, say commands.R in the working
directory work, they may be executed at any time in an R session with the
command ____________
a) source(“commands.R”)
b) exec(“commands.R”)
c) execute(“commands.R”)
d) exect(“command.R”)
View Answer
Answer: a
Explanation: For Windows, Source is also available on the File menu.
7. _______ will divert all subsequent output from the console to an external file.
a) sink
b) div
c) exp
d) exc
View Answer
Answer: a
Explanation: sink() restores it to the console once again.
8. The entities that R creates and manipulates are known as ________
a) objects
b) task
c) container
d) packages
View Answer
Answer: a
Explanation: These may be variables, arrays of numbers, character strings,
functions, or more general structures built from such components.
9. Which of the following can be used to display the names of (most of) the
objects which are currently stored within R?
a) object()
b) objects()
c) list()
d) class()
View Answer
Answer: b
Explanation: During an R session, objects are created and stored by name.
10. Collection of objects currently stored in R is called as ________________
a) package
b) workspace
c) list
d) task
View Answer
Answer: b
Explanation: All objects created during an R session can be stored permanently
in a file for use in future R sessions.
is set of R Programming Language Multiple Choice Questions & Answers (MCQs)
focuses on “Console Input and Evaluation – 2”.
1. What will be the output of the following R function?
ADVERTISEMENT
ab <- list(1, 2, 3, "X", "Y", "Z")
dim(ab) <- c(3,2)
print(ab)
a)
1 “X”
2 “Y”
3 “ Z”
b)
1 “X”
2 “Y”
3 “ Y”
c)
1 “W”
2 “Y”
3 “ Z”
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects.
Participate Now!
ADVERTISEMENT
d) Error
View Answer
Answer: a
Explanation: List is a special type of vector that can contain elements of
different classes. Lists is a very important data type in R. Lists can be created
using the list() function, which takes an arbitrary number of arguments.
2. What is the meaning of the following R function?
x <- c(4, 5, 1, 2, 3, 3, 4, 4, 5, 6)
x <- [Link](x)
a) x becomes a factor
b) x is a factor
c) x does not exist
d) x is not a vector
View Answer
Answer: a
Explanation: Factors are used to represent categorical data and can unordered
and ordered. One can think of a factor as an integer vector where each integer
has a label. Factors are important in statistical modelling and are treated
specially by modelling functions like lm() and glm().
advertisement
3. What is the meaning of the following R function?
print( sqrt(2) )
a) 1.414314
b) 1.414214
c) Error
d) 14.1414
View Answer
Answer: b
Explanation: Functions are often used to encapsulate a sequence of expressions
that need to be executed numerous times, perhaps under slightly different
conditions. Functions are also often written when code must be shared with
others.
4. What will be the output of the following R function?
d <- date()
d
a) Prints todays date
b) Prints some date
c) Prints exact present time and date
d) Error
View Answer
Answer: c
Explanation: Dates are represented by the Date class and can be coerced from a
character string using the [Link]() function. This is a common way to end in R
with a Date. There are other alternatives to print date too.
5. What will be the output of the following R function?
paste("Everybody", "is", “a” , "warrior")
a) “Everybody”, “is”, “a” , “warrior”
b) Everybody is a warrior
c) Everybody”, “is”, “a” , “warrior
d) “Everybody is a warrior”
View Answer
Answer: d
Explanation: Both paste() and cat() print out text to the console by combining
multiple character vectors together, it is impossible for those functions to know
in advance how many character vectors will be passed to the function by the
user.
6. What will be the output of the following R function?
cat("Everybody", "is", "a", “warrior”,sep="*")
a) “Everybody”, “is”, “a” , “warrior”
b) Everybody*is*a*warrior
c) Everybody”, “is”, “a” , “warrior
d) “Everybody*is*a*warrior”
View Answer
Answer: b
Explanation: Both paste() and cat() print out text to the console by combining
multiple character vectors together, it is impossible to those functions to know
in advance how many character vectors will be passed to the function by the
user.
7. What will be the output of the following R function?
nchar()
a) no. of characters
b) first 5 characters
c) last 5 characters
d) Does not exist
View Answer
Answer: a
Explanation: nchar will print the number of characters as output. It does not
print the whole characters, it just prints the number. It does not print first 5 and
also last 5 characters of the input string.
8. What will be the output of the following R function?
d <- diag(5, nrow=2, ncol=2)
d
a)
5 1
0 5
b)
5 0
5 5
c)
5 0
15 5
d)
5 0
0 5
View Answer
Answer: d
Explanation: Generally, the matrix can be printed with a matrix function. But the
diagonal matrix can be easily created with diag function. In the question, we
have in the same way.
9. What will be the output of the following R function?
[Link]()
a) Tomorrow date
b) Present date
c) Some date
d) Yesterday date
View Answer
Answer: b
Explanation: [Link] and also [Link] returns the system’s idea of the current
date with and without time. [Link] returns an absolute date-time value which
can be converted to various time zones and may return different days. [Link]
returns the current day in the current time zone.
10. What will be the output of the following R function?
[Link]()
a) Tomorrow date and time
b) Present date and time
c) Some date
d) Yesterday date and time
View Answer
Answer: b
Explanation: [Link] returns a present date-time value which can be converted
to various time zones and may return different days. [Link] and also [Link]
returns the system’s idea of the current date with and without time.