I have various objects defined but I am trying to remove a set of elements in
one vector from another and using the loops at the end of this post but I am
getting the error at the very end of this post.
int [1:1206, 1:2] 399 653 600 271 870 185 298 620 119 162 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:1206] "hirschsprung.399" "peritoneal.653" "occult.600"
"enteroclysis.271" ...
..$ : chr [1:2] "row" "col"
#Trying to delete all variables in my correlation matrix x that have
correlation greater than .6
answer2<-which(((x >.6) | (x<(-.6))), arr.ind = TRUE)
#also need to delete the diagonal entries of x (where a var is correlated
with itself) because my goal is to variables from mydataN but a variable
being correlated with itself is not a reason to drop it:
answer3<-answer2
answer3 <- answer2[answer2[,1]!=answer2[,2],]
#so now the second row of answer3 is a list of highly correlated variables.
#now take the entire 2nd column answer3 :in other words we want a list of
correlated variables that we are going to eliminate.
uniqueFromColumn2ofAnswer2=unique(answer3[,2])
str(uniqueFromColumn2ofAnswer2)
int [1:561] 1 3 5 10 12 13 15 17 18 19 ...
#now create a holder for mydataN minus those columns which have "bad" or
highly correlated variables.
mydataNMinusHighCorForAll <- mydataN
#and now go ahead and take them out:
for (i in uniqueFromColumn2ofAnswer2) {for (j in
mydataN[0,]){if(i==j){mydataNMinusHighCorForAll[,-j]}}}
Error in if (i == j) { : argument is of length zero