If you use sapply
you don't need to create the vector yourself and you don't need to grow it (sapply
takes care of all that). You probably want something like this:
example.function <- function(threshold = 0) {
example.vector <- sapply(1:30, function(i) {
## Cutting for space and to avoid giving away answers.
## a few lines get the complete records in each
## file and count them.
if(complete.record.count > threshold) {
new.correlation <- cor(complete.record$val1, complete.record$val2)
} else {
new.correlation <- NA
}
new.correlation #return value of anonymous function
})
# more null value handling#
example.vector #return value of example.function
}
However, it is unclear how the index i
factors into the anonymous function and the question is not reproducible ...