I think I understand the confusion. I bet 4 Kit Kit coats, if you type ncol(rn)
, you'll see that rn has 2 columns, not 3, as you might expect. The first “column” you see on the screen is not really a column - it's just the row names for the rn object. Enter rownames(rn)
to confirm this. The last column rn that you want to order is therefore rn [, 2], not rn [, 3]. The message "subscript out of bounds" appears because you asked R to order in column 3, but rn does not have column 3.
Here is my short detective trail for anyone interested in what is actually an object of "importance" ... I installed the library (randomforest) and then ran an example from the online documentation:
set.seed(4543) data(mtcars) mtcars.rf <- randomForest(mpg ~ ., data=mtcars, ntree=1000, keep.forest=FALSE, importance=TRUE) importance(mtcars.rf)
Turns off the “importance” object in this case looks like this (the first few lines only to save space):
%IncMSE IncNodePurity cyl 17.058932 181.70840 disp 19.203139 242.86776 hp 17.708221 191.15919 ...
Obviously, ncol (value (mtcars.rf)) is 2, and line names are likely to be the cause of the confusion :)
source share