I have a for loop which prints a result, just a single number and an i(for 1:10)
(count <- (length(which(colSums(data2[, -8])==0))))
print(i)
When I run all parts of the loop manually it prints the correct count(decreasing in value). And I could manually put all the values in excel to plot. However, Id like in my loop for count and i to be added to a new data frame, so I can run this a thousand times to get a reliable result.
And get a dataframe like this:
i count
1 10
2 9
3 8
4 6
5 4
6 4
7 4
8 3
9 2
10 0
So my question basically is: how do I extract 'count' and 'i' and create a dataframe to fit this in(make a row for each i).
Datasets and the rest of the loop is irrelevant for the solution I think.
Any help would be appreciated, cheers Jasper
EDIT
My current loop
for(i in 1:10) {
data2 <- data2[-sample(nrow(data2),size=1,replace=FALSE),]
(count <- (length(which(colSums(data2[, -8])==0))))
print(i)
}
countis a single number, independent ofiin the code you've written...?dataand within the loop createdata2 <- data[sample(1:nrow(data),10),], but I can only guess.