-
Notifications
You must be signed in to change notification settings - Fork 0
/
day 6.R
67 lines (54 loc) · 1.14 KB
/
day 6.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
fact_func <- function(x){
str_count <- nchar(x)
fact <- 1
for (i in 1:str_count){
fact <- fact * i
}
return (fact)
}
mean_val <- function(fact, x){
len_x <- nchar(x)
formular <- fact/len_x
return (formular)
}
p <- fact_func("jamie")
x <- mean_val(p, "jamie")
print(p)
print(x)
#######standard dev from here#########
sum_dev <- function(vector_val){
sum_val <- 0
for (i in vector_val){
sum_val <- sum_val + i
}
return (sum_val)
}
mean_vector <- function(sum_val, vector_val){
count_vec <- length(vector_val)
mean.val <- sum_val/count_vec
return (mean.val)
}
ind_flat <- function(vector_val, mean.val){
p_vec <- c()
for (i in vector_val){
p <- (i - mean.val)**2
p_vec <- c(p_vec, p)
}
return (p_vec)
}
sum_vect <- function(p_vec){
sum_vec <- 0
for (i in p_vec){
sum_vec <- i + sum_vec
}
return (sum_vec)
}
val_vector <- c(3, 6, 8, 3, 5, 9, 11)
h <- sum_dev(val_vector)
g <- mean_vector(h,val_vector)
vect_ret <- ind_flat(val_vector, g)
sum_myvec <- sum_vect(vect_ret)
print(g)
print(h)
print(vect_ret)
print(sum_myvec)