The challenge :编写一个函数,该函数获取数据文件目录和完整案例的阈值,并计算监视器位置的硫酸盐和硝酸盐之间的相关性,其中完全观察到的病例数(在所有变量上)大于阈值 . 该函数应返回满足阈值要求的监视器的相关向量 . 如果没有监视器满足阈值要求,则该函数应返回长度为0的数字向量 .
The Code :
corr <- function(directory, threshold = 0){
## This part creates the list for the creation of coorelation data between Nitrate and Sulfite
list <- list.files(directory, full.names = TRUE)
data1 <- do.call(rbind, lapply(list, read.csv, header = TRUE))
## This provides for interaction between parameters provided and column data
data1.subO <- data1[data1$sulfate > threshold, drop = FALSE]
data1.sub2O <- data1.subO[data1.subO$nitrate > threshold, drop = FALSE]
data1.sub3O <- na.omit(data1.sub2O)
print(cor(data1.sub3O))
}
The Errors :
> corr("specdata", 300)
Show Traceback
Rerun with Debug
Error in `[.data.frame`(data1, data1$sulfate > threshold, drop = FALSE) :
undefined columns selected In addition: Warning message:
In `[.data.frame`(data1, data1$sulfate > threshold, drop = FALSE) :
'drop' argument will be ignored
问题:
如何告诉R我要关联来自'硫酸盐'和'硝酸盐'列的信息?请展示示例,解释等 . 谢谢!``