f <- function(directory){
files_list <- list.files(directory, full.names=T)
u<-numeric()
for (i in 1:332){
dat <- read.csv(files_list[i])
m <- na.omit(dat)
c <- nrow(m)
if (c>150){
x<-m$"nitrate"
y<-m$"sulfate"
u<-cbind(u,cor(x,y))
}
}
u
}
想要生成数值型的结果,例如
##[1] -0.01896 -0.14051 -0.04390 -0.12351
但是现在的结果是
[,1] [,2] [,3] [,4] [,5]
[1,] -0.01895754 -0.1405125 -0.04389737 -0.06815956 -0.1235067
[,6] [,7] [,8] [,9] [,10]
[1,] -0.07588814 -0.1596737 -0.08684194 0.7631288 -0.1578286