Turning a dataframe into a named vector

前端 未结 2 1057
野的像风
野的像风 2021-01-22 15:08

I applied a model (wordscore) on my dfm. As a result I got an object of output whose class is \"textmodel_wordscores\" \"textmodel\" \"list\". I am interested in the output \"wo

相关标签:
2条回答
  • 2021-01-22 15:32

    You can do:

    with(df, setNames(Score, Words))
    
    commitment   progress  implement   decision    message    deficit 
    -0.9843452 -0.9831530 -0.9785868 -0.9777243 -0.9762919 -0.9752300 
    
    0 讨论(0)
  • 2021-01-22 15:49

    We can also use deframe

    library(tibble)
    deframe(df)
    #commitment   progress  implement   decision    message    deficit 
    #-0.9843452 -0.9831530 -0.9785868 -0.9777243 -0.9762919 -0.9752300 
    

    In base R, names<- can be used as well

    with(df, `names<-`(Score, Words))
    
    0 讨论(0)
提交回复
热议问题