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.
> str(x) num [1:923, 1:923] 1 -0.00371 -0.00102 -0.00204 -0.00102 ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:923] "a4.1" "abdomen.2" "abdomimal.3" "abdominal.4" ... ..$ : chr [1:923] "a4.1" "abdomen.2" "abdomimal.3" "abdominal.4" ... > str(answer2) int [1:2129, 1:2] 1 399 653 2 3 600 4 5 271 870 ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:2129] "a4.1" "hirschsprung.399" "peritoneal.653" "abdomen.2" ... ..$ : chr [1:2] "row" "col" > str(answer3) 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 -- View this message in context: http://www.nabble.com/removing-entries-from-one-vector-that-are-in-another-tp23241912p23241912.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.