【发布时间】:2020-09-09 07:09:12
【问题描述】:
我正在编写以下函数来创建相关矩阵并找到高度相关 (>0.75) 的值:
var.cor <- function(data, cols){
cor.mat <- cor(data [, cols])
cor.mat <- round(cor.mat, 2)
high.corr <- findCorrelation(cor.mat, cutoff = 0.75)
print(cor.mat)
print(high.corr)
}
我想给函数一个列号范围(即var.cor(data =dat, 10:20) 将为列 10:20 运行函数。在第二行指定 cols 的正确方法是什么?功能?当我运行var.cor("dat1", 10:20) 时,我收到一条错误消息:
Error in data[, cols] : incorrect number of dimensions
【问题讨论】:
-
能否提供reproducable example?
标签: r function functional-programming