24 lines
662 B
R
24 lines
662 B
R
#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) |