The Art of R Programming

(WallPaper) #1
A number of other generic functions are defined for this class. See
the online help forlm()for details. (Using R’s online documentation is
discussed in Section 1.7.)
To estimate a prediction equation for exam 2 from both the exam 1
and the quiz scores, we would use the+notation:

> lmb <- lm(examsquiz[,2] ~ examsquiz[,1] + examsquiz[,3])

Note that the+doesn’t mean that we compute the sum of the two quantities.
It is merely a delimiter in our list of predictor variables.

1.6 Startup and Shutdown......................................................


Like that of many sophisticated software applications, R’s behavior can be
customized using startup files. In addition, R can save all or part of a session,
such as a record of what you did, to an output file. If there are R commands
that you would like to execute at the beginning of every R session, you can
place them in a file called.Rprofilelocated either in your home directory
or in the directory from which you are running R. The latter directory is
searched for this file first, which allows you to have custom profiles for par-
ticular projects.
For example, to set the text editor that R invokes if you calledit(), you
can use a line in.Rprofilelike this (if you’re on a Linux system):

options(editor="/usr/bin/vim")

R’soptions()function is used for configuration, that is, to tweak various
settings. You can specify the full path to your own editor, using the notation
(slashes or backslashes) appropriate to your operating system.
As another example, in.Rprofileon my Linux machine at home, I have
the following line:

.libPaths("/home/nm/R")

This automatically adds a directory that contains all my auxiliary packages to
my R search path.
Like most programs, R has the notion of yourcurrent working directory.
Upon startup, this will be the directory from which you launched R, if you’re
using Linux or a Mac. In Windows, it will probably be yourDocumentsfolder.
If you then reference files during your R session, they will be assumed to be
in that directory. You can always check your current directory by typing the
following:

> getwd()

Getting Started 19
Free download pdf