-
Notifications
You must be signed in to change notification settings - Fork 0
/
session-02.R
64 lines (50 loc) · 1.47 KB
/
session-02.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
# Make a function to convert fahrenheit to kelvin
fahr_to_kelvin <- function(temp) {
kelvin <- ((temp - 32) * (5 / 9)) + 273.15
return(kelvin)
}
fahr_to_kelvin(32)
?fahr_to_kelvin
fahr_to_kelvin(212)
# Function to convert kelvin to celsius
kelvin_to_celsius <- function(temp) {
celsius <- temp - 273.15
return(celsius)
}
kelvin_to_celsius(0)
# Convert fahrenheit to celsius
fahr_to_celsius <- function(temp) {
temp_k <- fahr_to_kelvin(temp)
result <- kelvin_to_celsius(temp_k)
return(result)
}
freezingpoint <- fahr_to_celsius(32.0)
kelvin_to_celsius(fahr_to_kelvin(32))
center <- function(data, desired) {
# Return a new vector containing the origianl data centered
# around the desired value.
# Example: center(c(1, 2, 3), 0) => c(-1, 0, 1)
new_data <- (data - mean(data)) + desired
return(new_data)
}
z <- c(0, 0, 0, 0)
center(z, 3)
dat <- read.csv(file = "data/inflammation-01.csv", header=FALSE)
center(dat[, 4], 0)
head(dat)
min(dat[, 4])
min(center(dat[, 4], 0))
max(dat[, 4])
max(center(dat[, 4], 0))
sd(dat[, 4]) - sd(center(dat[, 4], 0))
analyze <- function(filename) {
dat <- read.csv(file = filename, header=FALSE)
ave_day_inflammation <- apply(dat, 2, mean)
plot(ave_day_inflammation)
max_day_inflammation <- apply(dat, 2, max)
plot(max_day_inflammation)
min_day_inflammation <- apply(dat, 2, min)
plot(min_day_inflammation)
}
analyze("data/inflammation-01.csv")
analyze("data/inflammation-02.csv")