- Home
- Interview Questions
- R Programming
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.
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.
rapply is recursive, and ideal for deeply nested objects like trees.
This is a classic split-apply-combine problem. Use tapply (or something from the plyr package).
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.
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.
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).
A package library is just a folder on your machine that contains R packages.
.libPaths returns a list of libraries.
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.