能否在R语言中创建此类数据汇总表格?若可行应使用哪个R包?
Absolutely! You can totally recreate the style of summary tables from Geiger, Raghunandan, and Riccardi (2014) in R—there are several solid packages that make this straightforward. Let me walk you through the best options:
Recommended R Packages for Recreating the Table Style
1. gt (Great Tables)
- This is my go-to for building polished, publication-ready tables. It gives you precise control over every detail—headers, cell styling, borders, summary rows, and more—perfect for matching the clean, professional look of academic finance papers like the one you're referencing.
- Here's a quick snippet to get you started with a structure similar to the paper's summaries:
# Install and load the package install.packages("gt") library(gt) # Sample data mirroring the paper's firm summary structure summary_data <- data.frame( Metric = c("Total Firms", "Firms with Going-Concern Opinions", "Bankrupt Firms"), Pre_Crisis = c(1200, 85, 42), Crisis_Period = c(1150, 162, 98), Post_Crisis = c(1250, 78, 39) ) # Build and style the table summary_data %>% gt() %>% tab_header( title = "Firm Summary by Crisis Period", subtitle = "Adapted from Geiger, Raghunandan, and Riccardi (2014)" ) %>% fmt_number(columns = 2:4, decimals = 0) %>% tab_style( style = cell_text(weight = "bold"), locations = cells_column_labels() ) %>% tab_spanner( label = "Time Period", columns = 2:4 ) %>% tab_options(table.border.top.style = "solid", table.border.bottom.style = "solid")
2. flextable
- If you need to export your table to Microsoft Word or Excel (super common for academic submissions),
flextableis a fantastic pick. It handles complex formatting seamlessly and preserves styling when exporting to these formats. - A big plus: It’s easy to add row/column totals or conditional formatting, which are likely features of the tables in the paper.
3. stargazer
- While it’s best known for regression output,
stargazercan also generate clean, minimalist summary tables. It’s ideal if you’re writing a LaTeX-based paper, as it outputs directly to LaTeX code that integrates smoothly with your document. - To use it, just structure your data as a data frame or matrix, then specify the output type with the
typeargument (e.g.,type = "latex"ortype = "html").
The exact styling will depend on the specific table you’re targeting from the paper, but all these packages let you tweak borders, font sizes, alignment, and even colors to match the original. Start with gt if you want a user-friendly, highly customizable solution that looks great in both HTML and PDF outputs.
内容的提问来源于stack exchange,提问作者jvdl
相关产品推荐
相关产品推荐

