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