I am working on a correlation matrix (corm) of 606 columns by 606 rows, and I have a variable called (X) that contains some column names. I want to pick these columns from the (corm).
> print(X)
[1] "VL" "IM" "2_EA" "Av"
[5] "Cit" "Wap" "Rp" "R"
[9] "H2e" "Wp" "As" "2"
[13] "HS" "Wep" "W" "p"
I apply the following command
corm2 <- corm[,X]
and I get this:
Error: subscript out of bounds
Any clue what is going wrong here?
Turning that comment into an answer:
Error: subscript out of boundshappens because some of the names inXare not column names to yourcormmatrix. In other words, you are trying to extract inexistent columns, hence the error message.It is probably because of a typo. You can run
setdiff(X, colnames(corm))to find out the culprit(s).