The Background:
I have a dataset that I’ve been given. The goal is to find out who’s been slacking on submitting their important forms.
I have the information (the names have been changed to protect the innocent, as well as if I make a mistake).
The data is separated into three columns; Business, Forms.Presented and Form.Title.
The Issue
When I run the code (below) I get a beautiful view of how I want it to look. This gives me separate tables based on Form.Title, so I can compare each individual form that should be presented by the business.
However, if I attempt to write.csv, write.table or write.xlsx, it gives me the data a different way.
Working:
> addmargins(with (Business_Forms, table (Business, Form.Presented., Form.Title)))
Funky:
write.xlsx(addmargins(with(Business_Forms, table(Business, Form.Presented.,Form.Title))), file = "C:/Users/Me/Desktop/Business.xlsx")
write.table(addmargins(with(Business_Forms, table(Business, Form.Presented.,Form.Title))), file = “clipboard”, sep= ”\t”)
The Funkiness:
What I expect to see is a simple, small set of tables based on the Form.Title field; exactly what I see in the console view.
Console view:
, , Form.Title = Any Known Allergens
        Form.Presented.
Business FALSE TRUE  Sum
  Food       0 1115 1115
  Planes     0    0    0
  Soda       0    0    0
  Trains     0    0    0
  Trucks     0    0    0
  Water      1    0    1
  Sum        1 1115 1116
, , Form.Title = Fuel Type
        Form.Presented.
Business. FALSE. TRUE.  Sum.
  Food       0    0    0
  Planes     0    0    0
  Soda       0    0    0
  Trains     3  204  207
  Trucks     0  172  172
  Water      0    0    0
  Sum        3  376  379
However, something’s happening between the console view and the spreadsheet. It runs and saves like it should, but instead of getting counts or frequencies broken down as I see them, it gets lumped differently.
Business    Form.Presented. Form.Title  Freq
Food        FALSE       Any Known Allergens 0
Planes      FALSE       Any Known Allergens 0
Soda        FALSE       Any Known Allergens 0
Trains      FALSE       Any Known Allergens 0
Trucks      FALSE       Any Known Allergens 0
Water       FALSE       Any Known Allergens 1
Sum         FALSE       Any Known Allergens 1
Food        TRUE        Any Known Allergens 1115
I can make it work by manipulating the information in excel, but that’s not why I’m using R.
Any advice would be greatly appreciated!
Update
I created a dataframe so the results can be replicated.
data1 <- c('Food','Water','Soda','Planes','Trains','Trucks')
data2 <- c('TRUE','FALSE','FALSE','TRUE','TRUE','TRUE')
data3 <- c('Safe For Moms','Any Known Allergens','Safe For Moms','MSDS/SDS','Offgas Fumes','Fuel Type')
Business<-c(data1,data1,data1,data1)
Form.Presented. <- c(data2,data2,data2,data2)
Form.Title <- c(data3,data3,data3,data3)
Business_Forms<-data.frame(Business,Form.Title,Form.Presented.)
If you run the code from before, it should work. I did test it before I typed this.
