with a very short and simple command you can unleash quite a bit
of processing on your data. In the next line we ask for the “mean”
(what non-data people call the average) of all of the ages and this
turns out to be 22 years. The command right afterwards, called
“range,” shows the lowest and highest ages in the list. Finally, just
for fun, we tried to issue the command “ﬁsh(myFamilyAges).”
Pretty much as you might expect, R does not contain a “ﬁsh()”
function and so we received an error message to that effect. This
shows another important principle for working with R: You can
freely try things out at anytime without fear of breaking anything.
If R can’t understand what you want to accomplish, or you haven’t
quite ﬁgured out how to do something, R will calmly respond with
an error message and will not make any other changes until you
give it a new command. The error messages from R are not always
super helpful, but with some strategies that the book will discuss
in future chapters you can break down the problem and ﬁgure out
how to get R to do what you want.
Let’s take stock for a moment. First, you should deﬁnitely try all of
the commands noted above on your own computer. You can read
about the commands in this book all you want, but you will learn a
lot more if you actually try things out. Second, if you try a com-
mand that is shown in these pages and it does not work for some
reason, you should try to ﬁgure out why. Begin by checking your
spelling and punctuation, because R is very persnickety about how
commands are typed. Remember that capitalization matters in R:
myFamilyAges is not the same as myfamilyages. If you verify that
you have typed a command just as you see in the book and it still
does not work, try to go online and look for some help. There’s lots
of help at http://stackoverﬂow.com
, at https://stat.ethz.ch
also at http://www.statmethods.net
/. If you can ﬁgure out what
went wrong on your own you will probably learn something very
valuable about working with R. Third, you should take a moment
to experiment a bit with each new set of commands that you learn.
For example, just using the commands shown in the last screen
shot you could do this totally new thing:
myRange <- range(myFamilyAges)
What would happen if you did that command, and then typed
“myRange” (without the double quotes) on the next command line
to report back what is stored there ? What would you see? Then
think about how that worked and try to imagine some other experi-
ments that you could try. The more you experiment on your own,
the more you will learn. Some of the best stuff ever invented for
computers was the result of just experimenting to see what was
possible. At this point, with just the few commands that you have
already tried, you already know the following things about R (and
How to install R on your computer and run it.
How to type commands on the R console.
The use of the “c()” function. Remember that “c” stands for con-
catenate, which just means to join things together. You can put a
list of items inside the parentheses, separated by commas.
That a vector is pretty much the most basic form of data storage
in R, and that it consists of a list of items of the same mode.
That a vector can be stored in a named location using the assign-
ment arrow (a left pointing arrow made of a dash and a less than
symbol, like this: “<-”).