r - Find largest 5 value less than 1, lowest 5 values -
i have large correlation matrix result in r - 30 items correlated against each other - array has 10,000 cells. want find largest 5 , smallest 5 results. how can this?
here's small portion - upper left corner - looks like:
pl1 v3 v4 v5 pl1 1.00000000 0.19905701 -0.02994034 -0.1533846 v3 0.19905701 1.00000000 0.09036472 0.1306054 v4 -0.02994034 0.09036472 1.00000000 0.1848030 v5 -0.15338465 0.13060539 0.18480296 1.0000000
the values in table between 1 & -1 , if helps, being correlation matrix upper half above diagonal duplicate of lower half below diagonal.
i need positive 5 less 1 , negative 5 including -1 if exists.
thanks in advance.
you want find largest , smallest correlations , know not what, values came from. it's easy.
x<-matrix(runif(25),5,5) cor<-cor(x) l <- length(cor) l1 <- length(cor[cor<1]) #the actual high , low correlation indexes corhigh <- order(cor)[(l1-4):l1] corlow <- order(cor)[1:5] #(if want view correlations cor[corlow] or cor[corhigh] works fine) #isolate them in matrix can see came corhighview <- cor corhighview[!1:l %in% corhigh] <- na corlowview <- cor corlowview[!1:l %in% corlow] <- na #look @ matrix target correlations sticking out sore thumb corlowview corhighview
Comments
Post a Comment