0

I am new in R and trying to convert VIF results into dataframe to feed it to ggplot:

vif_values <- car::vif(model_vif_check_aliased$finalModel)
vif_values

############ output ###############
       duration       nr.employed         euribor3m             pdays 
         1.016706         75.587546         80.930134         10.216410 
     emp.var.rate  poutcome.success         month.mar     cons.conf.idx 
        64.542469          9.190354          1.077018          3.972748 
contact.telephone          previous               age    cons.price.idx 
         2.091533          1.850089          1.185461         28.614339 
        month.jun       job.retired 
         3.936681          1.198350 

ISSUE: When I convert this into data frame then name of variables comes into index rather than as a separate column:

as.data.frame(vif_values) 

############ output ###############
 
               vif_values
               <dbl>
duration       1.016706         
nr.employed    75.587546            
euribor3m      80.930134            
pdays          10.216410            
emp.var.rate    64.542469           
poutcome.success    9.190354            
month.mar      1.077018         
cons.conf.idx   3.972748            
contact.telephone   2.091533            
previous       1.850089

How do I make this as data frame of two column so that I can use this in ggplot to create a barplot of variable names with their values ?

ggplot(aes(x=var_name, y=vif_values)+
 geom_col(col="blue")+
 coord_flip()
ViSa
  • 1,563
  • 8
  • 30
  • 1
    `df <- cbind(var_name = rownames(df), df)` and then `rownames(df) <- NULL` –  Aug 01 '23 at 06:37

1 Answers1

0

This should work: df$var_name = rownames(df), where df is your data frame

  • 1
    thanks @Ricardo Semião e Castro I was trying with `index`, `set index` etc. and your code worked. I will accept the answer as soon as it let me . – ViSa Oct 29 '20 at 18:08