How to sort a data frame in R

Since your data.frame only has one column, you need to set drop=FALSE to prevent the dimensions from being dropped:

weights[order(-weights$attr_importance),,drop=FALSE]
#         attr_importance
# our         0.125433292
# all         0.098185517
# address     0.090686474
# over        0.075182467
# make        0.049630556
# num3d       0.007122618

Leave a Comment