>
4 Console
4.1 R interface
In contrast to many other statistical software packages that use a point-and-click interface, e.g. SPSS, JMP, Stata, etc, R has a command-line interface. The command line has a command prompt, e.g. >
, see below.
This means, that you will be entering commands on this command line and hitting enter to execute them, e.g.
help()
Use the up arrow to recover past commands.
hepl()
help() # Use up arrow and fix
4.2 R GUI (or RStudio)
Most likely, you are using a graphical user interface (GUI) and therefore, in addition, to the command line, you also have a windowed version of R with some point-and-click options, e.g. File, Edit, and Help.
In particular, there is an editor to create a new R script. So rather than entering commands on the command line, you will write commands in a script and then send those commands to the command line using Ctrl-R
(PC) or Command-Enter
(Mac).
= 1
a = 2
b + b a
[1] 3
Multiple lines can be run in sequence by selecting them and then using Ctrl-R
(PC) or Command-Enter
(Mac).
4.3 Intro Activity
One of the most effective ways to use this documentation is to cut-and-paste the commands into a script and then execute them.
Cut-and-paste the following commands into a new script and then run those commands directly from the script using Ctrl-R
(PC) or Command-Enter
(Mac).
<- 1:10
x <- rep(c(1,2), each=5)
y <- lm(y~x)
m <- summary(m) s
Now, look at the result of each line
x
y
m
s$r.squared s
Click for solution
x
[1] 1 2 3 4 5 6 7 8 9 10
y
[1] 1 1 1 1 1 2 2 2 2 2
m
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
0.6667 0.1515
s
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-0.4242 -0.1667 0.0000 0.1667 0.4242
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.6667 0.1880 3.546 0.00756 **
x 0.1515 0.0303 5.000 0.00105 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.2752 on 8 degrees of freedom
Multiple R-squared: 0.7576, Adjusted R-squared: 0.7273
F-statistic: 25 on 1 and 8 DF, p-value: 0.001053
$r.squared s
[1] 0.7575758