I have a matrix of about 1000 lines of X 500, I am trying to establish a correlation matrix for these variables with names, not numbers, so the result should look like this:
variable1 variable2 variable3 variable4 ... mrv1 mrv2 mrv3 mrv4 ... smrv1 smrv2 smrv3 smrv4 ... . . . . . . . . . . . .
where mrv1 = Large associated variable with variable1, smrv1 = second most related variable, etc.
I made a correlation matrix, but using a for loop and a very complex command (perhaps the worst command of all time, but it really works!). I look forward to setting this with the proper command, here is the command I'm using now.
mydata <- read.csv("location", header=TRUE, sep=",") lgn <- length(mydata) crm <- cor(mydata) k <- crm[,1] K <- data.frame(rev(sort(k))) A <- data.frame(rownames(K)) for (x in 2:lgn){ k <- crm[,x] K <- data.frame(rev(sort(k))) B <- data.frame(rownames(K)) A <- cbind(A,B) }
Any ideas for a simpler, more reliable team?
Thanks,
Error404
source share