From 7df5894056a177da62caebb45ca867881c03f2d7 Mon Sep 17 00:00:00 2001 From: Matan Horovitz Date: Wed, 23 Nov 2022 15:50:29 +0200 Subject: [PATCH] more lectures --- 23112022.R | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 23112022.R diff --git a/23112022.R b/23112022.R new file mode 100644 index 0000000..05aee4e --- /dev/null +++ b/23112022.R @@ -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) \ No newline at end of file