I create a vector called predictions, and the vector should be added new value in the sapply loop function.
However, when the loop finished, the predictions vector is still empty.
Then I tried predictions <- c(predictions, 1)
in the command line for testing, and find 1 is added into predictions successfully.
It confused me, am I missing something to make it work?
# create an empty vector
predictions <- c()
# loop
sapply(1:rows.test.coords, function(i){
each.test.row <- test.coords[i,]
speciesName <- each.test.row[3]
location <- c(each.test.row[1], each.test.row[2])
row.matrix <- matrix(as.matrix(as.numeric(location)),ncol=2)
# Get numeric value one.pre and going to add into predictions vector
one.pre <- apply(row.matrix,1,pred,models[[speciesName]])
# Add element into vector
predictions <- c(predictions, one.pre)
})