more lectures

This commit is contained in:
2022-11-21 16:59:23 +02:00
parent 84fda70cc6
commit f7850cf2bb
2 changed files with 34 additions and 0 deletions

20
flip.R Normal file
View File

@@ -0,0 +1,20 @@
count = 100
flip <- sample(c("head","tail"), count, replace =T, prob = c(0.75,0.25))
table(flip)
is_head <- flip == "head"
table(is_head)
#Each TRUE counts as 1, and FALSE as 0; thus you can figure out amount of heads.
sum(is_head)
freq <- c(1:length(is_head))
for (result in 1:length(is_head)) {
freq[result] <- sum(is_head[1:result])
}
rel_freq <- freq/1:length(is_head)
plot(rel_freq)
#####
a <- rep(0,count)
for (i in 1:count) {
a[i] <- i^2
}
#SEE cumsum