-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mosthighlycorrelated function error #1
Comments
Dear Keith, Thanks for letting me know this, I will fix it as soon as I can find time. Kind Regards, -----Original Message----- Running the following function from your book on multvariate analysis results in the below error (at the bottom). mosthighlycorrelated <- function(mydataframe,numtoreport) find the correlationscormatrix <- cor(mydataframe) set the correlations on the diagonal or lower triangle to zero,so they will not be reported as the highest ones:diag(cormatrix) <- 0 find the dimensions of the matrix, and the row names:numrows <- nrow(cormatrix) find the highest correlationssorted <- sort(abs(cormatrix),decreasing=TRUE) find the pair of variables with this correlationfor (j in 1:(numrows-1)) Error reported from r 2.14: Reply to this email directly or view it on GitHub: |
Dear Keith, I've finally got around to looking at this (sorry about the delay). I'm using 2.15.1 and don't get this error using this function on the wine[2:14] data-frame in the example on the webpage. Is this the input you are using? Regards, |
So how was this fixed. I have the same error message |
Running the following function from your book on multvariate analysis results in the below error (at the bottom).
mosthighlycorrelated <- function(mydataframe,numtoreport)
{
find the correlations
cormatrix <- cor(mydataframe)
set the correlations on the diagonal or lower triangle to zero,
so they will not be reported as the highest ones:
diag(cormatrix) <- 0
cormatrix[lower.tri(cormatrix)] <- 0
find the dimensions of the matrix, and the row names:
numrows <- nrow(cormatrix)
therownames <- rownames(cormatrix)
find the highest correlations
sorted <- sort(abs(cormatrix),decreasing=TRUE)
for (i in 1:numtoreport)
{
corri <- sorted[i]
find the pair of variables with this correlation
for (j in 1:(numrows-1))
{
for (k in (j+1):numrows)
{
corrjk <- cormatrix[j,k]
if (corri == abs(corrjk))
{
rowname <- therownames[j]
colname <- therownames[k]
print(paste("i=",i,"variables",rowname,"and",colname,"correlation=",corrjk))
}
}
}
}
}
Error reported from r 2.14:
Error in if (corri == abs(corrjk)) { : missing value where TRUE/FALSE needed
The text was updated successfully, but these errors were encountered: