-
Notifications
You must be signed in to change notification settings - Fork 0
/
session-01.R
82 lines (57 loc) · 1.3 KB
/
session-01.R
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
# Set relevant working directory
setwd("~/Desktop/workshop")
# Load data in:
read.csv(file = "data/inflammation-01.csv", header=FALSE)
weight_kg <- 57.5
# Calculate weight in pounds:
weight_lb <- 2.2 * weight_kg
weight_lb
weight_kg <- 100.0
# Read first inflammation dataset into R:
dat <- read.csv(file = "data/inflammation-01.csv", header=FALSE)
head(dat)
class(dat)
dim(dat)
dat[1, 1]
dat[1:4, 1:10]
dat[c(3, 8, 37, 56), c(10, 14, 29)]
dat[5, ]
dat[, 10]
patient_1 <- dat[1,]
patient_1
max(patient_1)
min(patient_1)
max(dat[1,])
mean(dat[,7])
median(dat[, 7])
mysd <- sd(dat[, 7])
mysd
# Let's find the average inflammation for each individual across all days:
avg_patient_inflammation <- apply(dat, 1, mean)
avg_patient_inflammation
avg_day_inflammation <- apply(dat, 2, mean)
?apply
animal <- c("m", "o", "n", "k", "e", "y")
animal[1:4]
animal[4:1]
4:1
animal[c(4, 3, 2, 1)]
rev(animal, -1)
?rev
rev(animal[1:4])
rev(animal[-5:-6])
-5:-6
animal[-1]
animal[-4]
animal[-1:-4]
-1:-4
animal[c(5, 2, 3)]
# What is the maximum inflammation across all days in our data?
max_day_inflammation <- apply(dat, 2, max)
plot(max_day_inflammation)
# What is the minimum?
min_day_inflammation <- apply(dat, 2, min)
plot(min_day_inflammation)
sd_day_inflammation <- apply(dat, 2, sd)
plot(sd_day_inflammation)
?plot