Why is my gt Table only displaying 2 columns and every other row of data when my df is 3 columns?

44 Views Asked by At

I have a df that has three columns: "Name", "Source", and "Average Disease Severity". I wanted to generate a simple table displaying this information. When I do so using the code below it only shows me a table with the "Source" and "Avg Disease Severity" columns. On top of this, in the numeric Avg column it is only showing the data for every other row? My df is character, characer, double. I added in the select and cols_label functions to try to force it to select all my columns but it is still not working. The Df is 38 rows in total.

Any reason why this is generating wrong?

Thank you,

My session info is: R version 4.2.2 (2022-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 22621)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] kableExtra_1.4.0 knitr_1.42 sjPlot_2.8.15 ggpubr_0.6.0 dunn.test_1.3.5 [6] lubridate_1.9.2 forcats_1.0.0 stringr_1.5.0 dplyr_1.1.2 purrr_1.0.1
[11] readr_2.1.4 tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.2 tidyverse_2.0.0 [16] gtsummary_1.7.2 gt_0.10.1 readxl_1.4.2

loaded via a namespace (and not attached): [1] nlme_3.1-160 fs_1.6.2 insight_0.19.7 bslib_0.4.2
[5] tools_4.2.2 backports_1.4.1 utf8_1.2.3 R6_2.5.1
[9] sjlabelled_1.2.0 colorspace_2.1-0 withr_2.5.0 tidyselect_1.2.0
[13] processx_3.8.1 emmeans_1.8.5 compiler_4.2.2 performance_0.10.8
[17] cli_3.6.1 xml2_1.3.4 labeling_0.4.2 bayestestR_0.13.1
[21] sass_0.4.5 scales_1.2.1 mvtnorm_1.1-3 systemfonts_1.0.4
[25] commonmark_1.9.0 digest_0.6.31 minqa_1.2.5 svglite_2.1.3
[29] rmarkdown_2.21 pkgconfig_2.0.3 htmltools_0.5.5 lme4_1.1-33
[33] highr_0.10 fastmap_1.1.1 rlang_1.1.0 rstudioapi_0.14
[37] jquerylib_0.1.4 farver_2.1.1 generics_0.1.3 jsonlite_1.8.4
[41] car_3.1-2 magrittr_2.0.3 Matrix_1.5-1 Rcpp_1.0.10
[45] munsell_0.5.0 fansi_1.0.4 abind_1.4-5 lifecycle_1.0.3
[49] stringi_1.7.12 carData_3.0-5 MASS_7.3-58.1 grid_4.2.2
[53] promises_1.2.0.1 sjmisc_2.8.9 lattice_0.20-45 ggeffects_1.3.4
[57] splines_4.2.2 chromote_0.2.0 sjstats_0.18.2 hms_1.1.3
[61] ps_1.7.5 pillar_1.9.0 boot_1.3-28 markdown_1.12
[65] estimability_1.4.1 ggsignif_0.6.4 glue_1.6.2 evaluate_0.20
[69] modelr_0.1.11 broom.helpers_1.14.0 vctrs_0.6.2 nloptr_2.0.3
[73] tzdb_0.3.0 cellranger_1.1.0 gtable_0.3.3 webshot2_0.1.1
[77] cachem_1.0.7 xfun_0.39 xtable_1.8-4 broom_1.0.4
[81] rstatix_0.7.2 later_1.3.0 viridisLite_0.4.1 websocket_1.4.1
[85] timechange_0.2.0

code is below.

> dput(head(Validation_Means_1))
structure(list(Name = c("Amelia", "Amethyst Improved", "Aroma 2", "Aromatto", "Aurelia", "Boxwood"), 
Source = c("NE Seed", "Johnny's Selected Seeds", "Johnny's Selected Seeds", "Hazzard's Seeds", "Renee's Garden", "Hazzard's Seeds"), 
`Average Disease Severity` = c(3.22, 3.75, 1.42, 4.5, 3.58, 4.42)), 
class = c("grouped_df", "tbl_df", "tbl", "data.frame"), 
row.names = c(NA, -6L), 
groups = structure(list(
    Name = c("Amelia", "Amethyst Improved", "Aroma 2", "Aromatto", "Aurelia", "Boxwood"), 
.rows = structure(list(1L, 2L, 3L, 4L, 5L, 6L), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -6L), .drop = TRUE))


Validation_Summary_Table <- Validation_Means_1 %>%
  select("Name", "Source", "Average Disease Severity"
         ) %>%
  gt() %>%
  tab_spanner(
    label = "Accession Information",
    columns = c("Name", "Source")
  ) %>%
  cols_label(
    Name = "Name",
    Source = "Source",
    `Average Disease Severity`= "Average Disease Severity"
  ) 
print(Validation_Summary_Table)
0

There are 0 best solutions below