Skip to content
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

Open
keithwlarson opened this issue Dec 11, 2011 · 3 comments
Open

mosthighlycorrelated function error #1

keithwlarson opened this issue Dec 11, 2011 · 3 comments
Assignees

Comments

@keithwlarson
Copy link

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

@avrilcoghlan
Copy link
Owner

Dear Keith,

Thanks for letting me know this, I will fix it as soon as I can find time.

Kind Regards,
Avril

-----Original Message-----
From: Keith Larson [mailto:[email protected]]
Sent: Sun 12/11/2011 3:09 PM
To: Coghlan, Avril
Subject: [LittleBookofRMultivariateAnalysis] mosthighlycorrelated function error (#1)

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


Reply to this email directly or view it on GitHub:
#1

@ghost ghost assigned avrilcoghlan Oct 24, 2012
@avrilcoghlan
Copy link
Owner

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?
If not, please could you send me the input, so I can try to replicate the error?

Regards,
Avril

@zkanfra
Copy link

zkanfra commented Jan 20, 2020

So how was this fixed. I have the same error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants