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

View Answer

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, …)

View Answer

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, …)

View Answer

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)

View Answer

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)

View Answer

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

View Answer

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)

View Answer

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

b) par(ask=TRUE)

c) par(omi=c(0,0,1,0) )

d) par(ask=False)

View Answer

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

View Answer

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?

a) titleAdd( “R language”)

b) title( “R language”)

c) titleBar( “R language”)

d) var(x, na.rm=TRUE)

View Answer

Explanation: This function can be used to add labels to a plot.

**Sanfoundry Global Education & Learning Series – R Programming Language.**

Here’s the list of Best Reference Books in R Programming Language.

__Here is complete set of 1000+ Multiple Choice Questions and Answers__.