-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWorkshop1.R
More file actions
68 lines (52 loc) · 939 Bytes
/
Workshop1.R
File metadata and controls
68 lines (52 loc) · 939 Bytes
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
5 + 2
# Variables
a <- 10
b <- a + 1
the.value <- b
the.value
the.index <- 2
the.value ^ the.index
# arrays and vectors
vector <- c(4, 5, 6, 7, 8)
vector
reverse.vector <- 8:4
reverse.vector
arr <- array(c(3, 4, 5), 6)
arr
arr2 <- array(3:6, 10)
arr2
v1 <- c(1, 6, 7, 9)
v2 <- c(-1, 2, 1, -2)
v1 + v2
v1 - v2
v1 * v2
v1 / v2
v1 ^ v2
v3 <- c(1, 2, 3, 4, 5)
v1 ^ v3 # error: object length is not multiple of shorter object length
v4 <- 1:8
v1 - v4
# remove variables from global environment
rm(a)
# basic arthematic built-in functions
mean(1:6)
mean(v1)
median(1:6)
a <- c(1, 8, 3, 9)
b <- c(2, 2, 1, 1)
d <- c(3, 4, 6, 81, 9)
prod(a)
prod(a) ^ (1 / length(b))
216 ^ (1 / 4)
length(b)
sum(a * b)
sum(a ^ b)
max(a, d, v1 * v2)
min(max(a), max(b))
# functions
meanFunc <- function(vec) {
output <- sum(vec) / length(vec)
output # this goes to the output stream like powershell and hence returned
}
meanFunc(1:6)
mean(1:6)