observed <- numeric(10) expected <- numeric(10) sum <- 0 random <- sort(sample(229354, 296)) observed[1] <- length(random[which(random < 22935.4)]) observed[2] <- length(random[which(random > 22935.4 & random < 45870.8)]) observed[3] <- length(random[which(random > 45870.8 & random < 68806.2)]) observed[4] <- length(random[which(random > 68806.2 & random < 91741.6)]) observed[5] <- length(random[which(random > 91741.6 & random < 114677)]) observed[6] <- length(random[which(random > 114677 & random < 137612.4)]) observed[7] <- length(random[which(random > 137612.4 & random < 160547.8)]) observed[8] <- length(random[which(random > 160547.8 & random < 183483.2)]) observed[9] <- length(random[which(random > 183483.2 & random < 206418.6)]) observed[10] <- length(random[which(random > 206418.6)]) for(i in 1:10) { expected[i] <- 29.6 } for(i in 1:10) { sum <- sum + ((observed[i] - expected[i])^2)/expected[i] }