Professional Documents
Culture Documents
lecture-07-slides-mm206-v2
lecture-07-slides-mm206-v2
lecture-07-slides-mm206-v2
Prof. D. Greenhalgh
• Powerful graphics
Getting started
and select your H: drive. Right click inside the window, and
select
• You need to do this only once. Each time you come to work
on the class, just save the relevant files into that directory.
Running R
• You will also see the R console window. This is where you
input commands. To make sure that any work is saved in
the MM206 directory that you have created, from the RGui
toolbar, select
• in this class the exercises and the exam will involve putting
R code and the results in a MS Word document.
• Make sure you save your script regularly by pressing Ctrl +S.
• Give the saved file suitable name and make sure it has a .R
file extension.
10
• + for addition
• - for subtraction
• * for multiplication
• / for division
• ∧ for powers
11
12
Answer:
[1] 43.29503
13
Constants
Examples
> pi
[1] 3.141593
> month.name
> x <- 53
> x
[1] 53
15
Note on assignments
53 -> x
x = 53
16
Data types
Vectors
Answer:
> MyNumbers
[1] 3 9 23 1 -78
18
Answer:
> MyNumbers[3]
[1] 23
19
Example:
Answer:
> n <- 5
> MyNumbers[n]
[1] -78
20
Missing Values
Example:
> x[4]
[1] NA
21
22
Answer
> mean(MyNumbers)
[1] -8.4
23
Answer
> 7/24
[1] 0.291666667
Answer:
26
27
3.0
l
2.8
l
mean.clutch
2.6
l
2.4
2.2
egg.complement
Finishing an R Session
• Make sure you have saved your R script and (for this class)
your Word document
28