-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lecture 1 Introduction.Rmd
87 lines (68 loc) · 1.68 KB
/
Lecture 1 Introduction.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
title: "Background to R"
author: "David McAllister"
date: "Monday 31st October, 2016"
output:
ioslides_presentation: default
---
## Aims and objectives
The aim of this course is to have a better feel for how R works as a language. At the end of this course you should be able to
* Clean and transform data in R
* describe how R's objects work
* Understand from the help menu how functions in base R and the packages work
* Use the apply family of functions
* Write simple functions
## Overview
Lectures followed by practicals
### Day 1
R Objects, subsetting, assigning
### Day 2
Attributes, functions, apply family of functions
## The S programming language
- Invented in AT&T labs - named after C
- S-Plus vs R (aka 'GNU S')
- Language first and foremost
```{r}
print ("Hello world")
```
## Everything that exists is an object. Everything that happens is a function call
### John Chambers
## We will focus on
1. **Objects** - *vectors*, matrices, arrays, lists, *dataframes*
2. **Functions** - mean(), sum(), glm()
## Some R code
```{r}
# create two objects, vectors
age <- c(34,55,60,75)
retire <- c(33L,5L,1L,10L)
# do some things with them
(age.retire <- age + retire)
mean(age)
mean(age.retire)
```
## Objects
**Everything** in R is an object.
age and age.retire are atomic vectors, a type of object
```{r}
class (age)
class (retire)
```
But so is mean, even though it is also a function
```{r}
mean2 <- mean
typeof(mean2)
```
## Functions
**Everything** you do in R you do with a function
```{r}
mean(1:3)
is.function (mean)
```
but even + is really a function
```{r}
`+`(2,3)
is.function (`+`)
```
## Our focus
### Understanding objects
### Understanding how functions interact with objects