# R Programming Questions and Answers – Commands – 3

«
»

This set of tough R Programming questions and answers focuses on “Commands – 3”.

1. Which of the following will reverse the order of values in x?
a) rev(x)
b) max(x, na.rm=TRUE)
c) all(x)
d) x%in%y

Explanation: rev provides a reversed version of its argument.

2. Which of the following finds row sums for each level of a grouping variable?
a) rowSums (x, na.rm = FALSE, dims = 1)
b) colMeans(x, na.rm = FALSE, dims = 1)
c) rowMeans(x, na.rm = FALSE, dims = 1)
d) rowsum(x, group, reorder = TRUE, …)

Explanation: False value leads to unexpected result.

3. Which of the following statement applies the function (FUN) to either rows (1) or columns (2) on object X?
a) apply(x,1,min)
b) apply(x,2,max)
c) col.max(x)
d) apply(X, MARGIN, FUN, …)

Explanation: apply(x,2,max) finds the maximum for each column.

4. Which of the following statement finds the maximum for each column?
a) apply(x,2,max)
b) col.max(x)
c) which.min(x)
d) which.max(x)

Explanation: col.max(x) is another way to find which column has the maximum value for each row.

5. which of the following statement tells the row with the minimum value for every column?
a) which.min(x)
b) which.max(x)
c) z=apply(x,1,which.min)
d) z=apply(1,1,which.max)

Explanation: which() function gives the TRUE indices of a logical object, allowing for array indices.

6. Which of the following may be used for linear regression?
a) X %*% Y
b) solve(A)
c) solve(A,B)
d) X \$*\$ Y

Explanation: solve(A,B) implies inverse of A * B.

7. Which of the following finds row sums for each level of a grouping variable?
a) as.numeric(x)
b) rowsum(x, group, reorder = TRUE, …)
c) as.order(x)
d) colSums (x, na.rm = FALSE, dims = 1)

Explanation: rowsum compute column sums across rows of a numeric matrix-like object for each level of a grouping variable.

8. Which of the following sets the size of the outer margins for the graph?
a) par(mfrow=c(nrow,mcol))
c) par(omi=c(0,0,1,0) )

Explanation: par can be used to set or query graphical parameters.

9. Which of the following function is used for plotting histogram?
a) hist()
b) histog()
c) histg()
d) histo()

Explanation: The generic function hist computes a histogram of the given data values.

10. Which of the following will add the title “R language” to the graph?
b) title( “R language”)
c) titleBar( “R language”)
d) var(x, na.rm=TRUE) 