How to convert outcome of table function to a dataframe in R

by Sagar Arora   Last Updated September 15, 2018 13:26 PM

df = data.frame(table(train$department , train$outcome)) 

here department and outcome both are factors so It gives me a dataframe which looks like in the given image

is_outcome is binary

df looks like this

containing only 2 variables(fields) while I want this department column to be a part of dataframe i.e a dataframe of 3 variables
0 1
Analytics 4840 512
Finance 2330 206
HR 2282 136
Legal 986 53
Operations 10325 1023
Procurement 6450 688
R&D 930 69
Sales & Marketing 15627 1213
Technology 6370 768

One way I learnt was...

df = data.frame(table(train$department , train$is_outcome))
write.csv(df,"df.csv")
rm(df)
df = read.csv("df.csv")
colnames(df) = c("department", "outcome_0","outcome_1")

but I cannot save file in everytime in my program

is there any way to do it directly.

Thanks for your time.



Related Questions


Can i use the eigenvalues as a weightage?

Updated May 13, 2018 09:26 AM

Replacing a node in a frozen Tensorflow model

Updated November 19, 2017 17:26 PM

Continuous or categorical data in data science

Updated January 29, 2018 18:26 PM


How to determine the VC-dimension of H (Theortical)?

Updated February 18, 2018 04:26 AM