R Programming Questions and Answers Part-6

1. A single element of a character vector is referred as ________
a) Character string
b) String
c) Data strings
d) Raw data

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 as.Date() function. This is a common way to end up with a Date object in R.

2. R files has an extension ______
a) .R
b) .S
c) .Rp
d) .c

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()

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

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

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.

6. Functionality of R is divided into a number of __________
a) Functions
b) Domains
c) Packages
d) Files

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()

Answer: b
Explanation: as.matrix function should be used to coerce a data frame to a matrix. It might seem that the as.matrix() 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”)
as.logical(x)
a) a b
b) “a” “b”
c) 1 1
d) Error

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. as.logical attempts to coerce its argument to be of a logical type.

9. What will be the output of the following R code?
a <- (“a” , “b”)
mode(a)
a) Character
b) Numeric
c) Complex
d) Integer

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

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.