I wrote a custom function to divide a data frame into k folds for k-fold cross-validation and want to print out the start and end indices of the folds to check if the division was done correctly. I'm using the paste()
function within a for
loop. When I run the function, I get no error but nothing gets printed. When I copy just the paste()
line into the terminal it prints the last index correctly, which suggests that the function was executed correctly. So why it is not printing the paste()
line from within the function? I would be grateful for any advice on this.
fold_index_counter = function(k, data){
n = nrow(data)
for (i in 1:k){
start = (n*i)/k
end = (n*(i+1))/k-1
paste("Fold no. ", i, " starts at row ", start, " and ends at row ", end, sep = "")
}
}
fold_index_counter(10, dat.cor.trim)