How to sort a data frame in R

前端 未结 3 1794
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 14:03

I am new to R, and want to sort a data frame called \"weights\". Here are the details:

>str(weights)
\'data.frame\':   57 obs. of  1 variable:
 $ attr_imp         


        
3条回答
  •  情话喂你
    2020-11-28 14:34

    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
    

提交回复
热议问题