Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning a dataframe into a named vector

Tags:

list

dataframe

r

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 "wordscores" which is a "numeric" object (this is what is said when class is applied to the object) that looks like this:

           extensive      fiscal_stimulus              measure           operation  automatic_stabiliser 
          0.96765485           0.98292581          -0.70247675           0.63275195           0.75272326 
                will 
         -0.04568423

Now I have a normal dataframe with two columns that looks like this:

df <- data.frame(Words = c("commitment", "progress", "implement", "decision", "message", "deficit"), Score = c(-0.984345245754151, -0.983153011766781, -0.978586816039627, -0.977724303324149, -0.976291875611652, -0.975229993562152))

    Words              Score
1 commitment -0.984345245754151
2   progress -0.983153011766781
3  implement -0.978586816039627
4   decision -0.977724303324149
5    message -0.976291875611652
6    deficit -0.975229993562152

I want this dataframe to become the same format as the one above. I tried to convert to a list but it keeps the double column framework.

like image 978
Rollo99 Avatar asked Oct 23 '25 04:10

Rollo99


1 Answers

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 
like image 52
tmfmnk Avatar answered Oct 24 '25 19:10

tmfmnk