correlation function always NA
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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