I am trying to write the following loop - this loop will:
- Randomly take 3 random samples of the iris dataset
- Check to see if the mean of the "Sepal.Length" column for all 3 random samples sum to less than 15
- Make sure that the number of common rows in all 3 random samples is no more 5
five = as.integer(5)
list_results <- list()
for (i in 1:100){
c1_i = c2_i = c3_i = ctotal_i = 0
while(c1_i + c2_i + c3_i < 15 && nrow_i < five ) {
num_1_i = sample_n(iris, 30)
num_2_i = sample_n(iris, 30)
num_3_i = sample_n(iris, 30)
c1_i = mean(num_1_i$Sepal.Length)
c2_i = mean(num_2_i$Sepal.Length)
c3_i = mean(num_3_i$Sepal.Length)
ctotal_i = c1_i + c2_i + c3_i
combined_i = rbind(num_1_i, num_2_i, num_3_i)
nrow_i = nrow(unique(combined_i[duplicated(combined_i), ]))
}
inter_results_i <- data.frame(i, c1_i, c2_i, c3_i, ctotal_i, nrow_i)
list_results[[i]] <- inter_results_i
}
When I run this loop, it is giving me an "empty result".
Can someone please show me what I am doing wrong and how I can try to correct this?
Thanks!