Compare commits

...

2 Commits

Author SHA1 Message Date
7df5894056 more lectures 2022-11-23 15:50:29 +02:00
f7850cf2bb more lectures 2022-11-21 16:59:23 +02:00
3 changed files with 58 additions and 0 deletions

14
03112022.R Normal file
View File

@@ -0,0 +1,14 @@
#Here's how to do stuff to the power of other stuff.
une = 8^2
#And how to do a factorial ([num]!)
duex = factorial(100)
#Excresice from slide with wee buggers. Also, this thing autocorrects comments. Wee shite.
wee_buggers = factorial(6) * factorial(4)
# This is a multiply ^ and it is important
colorful_wee_buggers = factorial(4) * factorial(5) * factorial(6) * factorial(3)
# That is the arrangement of the groups ^
#Now, try being a bastard.
vectroful_wee_buggers = c(4,5,6)
for (wee_bugger in vectroful_wee_buggers) {
print(wee_bugger)
}

24
23112022.R Normal file
View File

@@ -0,0 +1,24 @@
#Specify number of elements
count=100
#Create vector of COUNT elements ranging from 1 to 6
hundred <- (sample(c(1:6), count, replace = T))
#Keep count of 1's in seperate variable
one_count = 0
#Iterate over array elements
###
for (i in hundred) {
#If current element is 1, add to count variable
if (i == 1) {
print("i is 1")
one_count = one_count + 1
}
}
### OR
also_one_count <- sum(hundred=="1")
###
cat("One count is", one_count, "and also", also_one_count)
###
rel_one=(one_count/count)
###OR
also_rel_one < - sum(hundred=="1")/length(hundred) #Why is this one different?
cat("Relative frequency of one is", rel_one, "and also", also_one_count)

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