R Programming Questions and Answers Part-9

1. Find the following type of vector?
a <- c(1,2,5.3,6,-2,4)
a) Numeric
b) Character
c) Integer
d) Logical

Answer: a
Explanation: 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
Explanation: 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
Explanation: 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
Explanation: 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: b
Explanation: 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
Explanation: 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
Explanation: 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
Explanation: 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
Explanation: 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
Explanation: 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.