I'm trying to find the correlations with this function but I just get NA for each input:
corr <- function(directory, threshold = 0) { filenames <- list.files(directory, pattern="*.csv", full.names=TRUE) csv <- lapply(filenames, read.csv) correlations <- c() c(correlations, lapply(csv, function(x){ cor(x$nitrate,x$sulfate) print(cor(x$nitrate,x$sulfate)) })) correlations }
If I change the function to print the nitrate and sulfate it does in fact have values, if I just pass in x to the cor function it complains about non-numeric values.
Why does it always print NA and not the actual correlation?