# 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
View Answer

Answer: a
Explanation: rev provides a reversed version of its argument.

advertisement

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

Answer: c
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

Answer: d
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

Answer: a
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

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

Advertisement: Join [email protected]

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

Answer: c
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

Answer: b
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

Answer: c
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

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

advertisement

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

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

To practice tough questions and answers on all areas of R Programming, Here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
advertisement Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter