I have developed the following code to create a table in r and export it to csv where I format it to insert into a word document. This example contains the total of each fruit and the month in which they were sold.
library (lubridate)
Table<-read.csv("Fruit.csv")
#Creates a month name column
Table$Month<- month(Table$Date, label=TRUE)
#Creates the frequency table
FreqTable<-addmargins(table(Table$Fruit, Table$Month))
#Exports to CSV
write.csv(FreqTable,"Table.csv")
The above produces a table that looks like:
I have 3 main questions about the table and Im not sure if they are possible to fix.
How can I add a title for the 1st column? I just want to add 'Fruit' as the column name.
The data I have goes up until the end of June, how can I remove all the remaining months out of the table for where there is no data? (July - Dec)
How can I change the row and column header 'sum' to 'Total'?
Any assistance would be appreciated.