I've been looking for a way of exporting my results (tables in particular) to excel or ppt but all I can find is exporting entire datasets or exporting tables to txt files.
Is any way of exporting:
tables from my console to excel (table format is not that important but it would be good to be able to export at least its content)
We don't really have enough info to help you out. Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.
This is a general request related to all types of tables renerated in R Studio console (such as table function, CrossTable from gmodels package or any other form of table)...
With general request comes general response
For export into Excel, you could use a function like openxlsx::write.xlsx() or readr::write_csv() (csv will be consumed by Excel without a problem)
For export to ppt, you could:
Save plots with ggplot2's ggsave() and then paste them into your ppt
Switch from an .R script to a .Rmd document and knit it as a presentation.
Feel free to explore every mentioned function by calling help on it in the console. You'll find out what arguments you need to pass and how to edit your outcome.
(for example, type ?write_csv in the console after loading the readr package)
library(readxl)
#> Warning: package 'readxl' was built under R version 3.4.4
df <- read_excel("C:/Users/sdanilowicz/Documents/Test File for tables.xlsx", sheet = "Sales")
df$year <- as.numeric(format(df$InterviewDate,'%Y'))
df$month <- as.numeric(format(df$InterviewDate,'%m'))
table(df$month)
#>
#> 10 11 12
#> 2 4 8
reprex()
#> Error in reprex(): could not find function "reprex"
Hey Slavek there is a nice example for the openxlsx::write.xlsx() function. It may be a easy solution for you
## Lists elements are written to individual worksheets, using list names as sheet names if available
l <- list("IRIS" = iris, "MTCATS" = mtcars, matrix(runif(1000), ncol = 5))
write.xlsx(l, "writeList1.xlsx", colNames = TRUE)
That is correct. Seems like the CrossTable function you're using is providing you with summary info, but it isn't quite a suitable data frame, I would not want this to end up in Excel.
If I was tasked with exporting these summary tables to Excel (for whatever reason), I'd probably wrangle the data a bit (a bit of dplyr and tidyr functions: group_by, summarise, gather() and spread should do it) and get the results in the format I want which is a data frame and not a markup/markdown table.
I hope others have a better advice for you. I do question the need to export summary statistics into Excel, but it is probably none of my business.
As taras mentioned before 'everything is possible' . So, your summary statistics have to be in a suitable data frame, otherwise you have to prepare your summary results before your export to an excel-file (you need some coding). So back to taras example:
Thank you but I don't need to export any form of summary (codes above) but full tables with results. Maybe the best option would be exporting ggplot plots with all data behind to ppt or excel (editable outputs)?
Full tables can be exported with write_csv() or any other weapon of choice, I think we touched on that before, but you said you don't want "the entire data frame", and so my question is: