corr <- function(directory, threshold = 0) {
  setwd("c:/users/hp1/desktop")
  files_full <- list.files(directory,full.names = TRUE)
  cr <- data.frame()
  j = 1
  for(i in 1:332)
  {
    y <- read.csv(files_full[i])
    z <- y[complete.cases(y),]
    if (nrow(z) > threshold){
      cr[j] <- cor(z[,'sulfate'], z[,'nitrate'], method = "pearson")
      j = j+1
      }
    }
  cr
  }
it's showing the following error:
Error in [<-.data.frame(*tmp*, j, value = -0.222552560758546) : 
  replacement has 1 row, data has 0 
I was expecting as j increments, values would get added to the cr dtaframe. however that is not happening.
please suggest necessary changes
 
    