Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Now you can work with x . First, add all numbers in the vector.

Typing
sum(x)
in the Scripts pane (remember to follow with Ctrl+R) executes the following line
in the Console pane:
> sum(x)
[1] 12
How about the average of the numbers in the vector x ?
That’s
mean(x)
in the Scripts pane, which (when followed by Ctrl+R) executes to
> mean(x)
[1] 4
in the Console pane.
As you type in the Scripts pane or in the Console pane, you’ll notice that helpful
information pops up. As you gain experience with RStudio, you’ll learn how to use
that information.
As I show you in Chapter 5, variance is a measure of how much a set of numbers
differs from their mean. What exactly is variance, and how do you calculate it?
I’ll
leave that for Chapter 5. For now, here’s how you use R to calculate variance:
> var(x)
[1] 1
In each case, you type a command and R evaluates it and displays the result.
Figure 2-6 shows what RStudio looks like after all these commands.
To end a session, select File ➪ Quit Session or press Ctrl+Q. As Figure 2-7 shows,
a dialog box opens and asks what you want to save from the session. Saving the
selections enables you to reopen the session where you left off the next time you
open RStudio (although the Console pane doesn’t save your work).
Pretty helpful, this RStudio.

You might also like