I am writing the following function that creates a correlation matrix and finds highly correlated (>0.75) values:
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)
}
I want to give the function a range of column numbers (i.e., var.cor(data =
dat, 10:20)
will run the function for columns 10:20. what is the correct way to specify cols
in the second line of the function? when I run var.cor("dat1", 10:20)
I get an error message:
Error in data[, cols] : incorrect number of dimensions