R Programming Questions and Answers Part-13

1. Which function can be used to determine the names assigned to a list?
a) Names
b) Name
c) Nam
d) Nem

Answer: a
Explanation: To determine the names assigned to a list, the names function can be used. Lists can be created using the list function. Like data frames, they can incorporate a mixture of modes into the one list and each component can be of a different length or size.

2. Joining two lists can be achieved either using the _________ function.
a) Concat
b) Join
c) Reduce
d) Delete

Answer: a
Explanation: Joining two lists can be achieved either using the concatenation function or the append function.

3. Which function gives the list as output?
a) Spline
b) Matrix
c) Vector
d) Alphabet

Answer: a
Explanation: There are also many functions within R that produce a list as output. Examples of these functions include spline(), density() and locator().Joining two lists can be achieved either using the concatenation function or the append function.

4. Density function gives output as ________
a) Matrix
b) Lists
c) Vector
d) Number

Answer: b
Explanation: There are also many functions within R that produce a list as output. Examples of these functions include spline(), density() and locator().

5. Locator function gives output as ___________
a) Matrix
b) Lists
c) Vector
d) Number

Answer: b
Explanation: To extract a sublist, we use single brackets. There are a number of ways of accessing the first component of a list. There are also many functions within R that produce a list as output. Examples of these functions include spline(), density() and locator().

6. The _________ function returns a list of densities (y) corresponding to bin values (x).
a) Spline
b) Density
c) Lists
d) Locator

Answer: a
Explanation: The spline function returns a list of densities (y) corresponding to bin values (x). These can be passed to the plot routine to produce a line graph of the density.

7. Point out the wrong statement?
a) is.nan() is used to test objects if they are NA
b) is.nan() is used to test for NaN
c) NA values have a class
d) NA values have a class, so there are integer NA, character NA, etc

Answer: a
Explanation: A NaN value is also NA but the converse is not true.

8. Data frames can be converted to a matrix by calling data _______
a) as.matr()
b) as.mat()
c) as.matrix()
d) as.max()

Answer: c
Explanation: as.matrix() function should be used to coerce a data frame to a matrix.

9. What will be the output of the following R code?
> x < - data.frame(foo = 1:4, bar = c(T, T, F, F))
> ncol(x)
a) 2
b) 4
c) 7
d) 9

Answer: a
Explanation: Data frames are represented as a special type of list where every element of the list has to have the same length.

10. Point out the correct statement?
a) Using factors with labels is better than using integers because factors are self-describing
b) Factors are used to represent categorical data and can be unordered or ordered
c) Factors are important in statistical modeling and are treated specially by modelling functions like lm() and glm()
d) All of the mentioned

Answer: d
Explanation: Having a variable that has values “Male” and “Female” is better than a variable that has values 1 and 2.