Home
41.
Name as many members of the apply family of functions as you can.

lapply, vapply, sapply, apply, mapply, and tapply were all discussed in the chapter, with eapply and rapply getting brief mentions too. Try apropos("apply") to see all of them.

42.
What is the difference between lapply, vapply, and sapply?

All three functions accept a list and apply a function to each element in turn. The difference is in the return value. lapply always returns a list, vapply always returns a vector or array as specified by a template, and sapply can return either.

43.
How might you loop over tree-like data?

rapply is recursive, and ideal for deeply nested objects like trees.

44.
Given some height data, how might you calculate a mean height by gender?

This is a classic split-apply-combine problem. Use tapply (or something from the plyr package).

45.
In the plyr package, what do the asterisks mean in a name like **ply?

In a name like **ply, the first asterisk denotes the type of the first input argument and the second asterisk denotes the type of the return value.

46.
What are the names of some R package repositories?

CRAN is by far the biggest package repository. Bioconductor, R-Forge, and RForge.net are others. There are also many packages on GitHub, Bitbucket, and Google Code.

47.
What is the difference between the library and require functions?

Both functions load a package, but library throws an error if it fails, whereas require returns a logical value (letting you do custom error handling).

48.
What is a package library?

A package library is just a folder on your machine that contains R packages.

49.
How might you find the locations of package libraries on your machine?

.libPaths returns a list of libraries.

50.
How do you get R to pretend that it is Internet Explorer?

R doesn’t do a great impression of Internet Explorer, but you can make it use Internet Explorer’s internet2.dll library for connecting to the Internet.