rtable-statisticsqwraps2

Why does my table_summary looks weird in r


total beginner and very hopeful someone can help me(: Wrote the following code to create a statistics summary table grouped by city, but my table turned out weird looking (instead of looking like a table, it displayed the table spacers). What should I do?

load('myData.RData')

#install.packages('qwraps2')
library(qwraps2)
options(qwraps2_markup = 'markdown')
summary_statistics <-
  list(
    "Hobby(hours/week)" =
      list(
        "mean (sd)" = ~qwraps2::mean_sd(myData$hobby_hr_week, na_rm = TRUE),
        "min" = ~min(myData$hobby_hr_week, na.rm = TRUE),
        "max" = ~max(myData$hobby_hr_week, na.rm = TRUE)
      ),
    "Work(hours/week)" =
      list(
        "mean (sd)" = ~qwraps2::mean_sd(myData$work_hr_week, na_rm = TRUE),
        "min" = ~min(myData$work_hr_week, na.rm = TRUE),
        "max" = ~max(myData$work_hr_week, na.rm = TRUE)
      ),
    "Wellness" =
      list(
        "mean (sd)" = ~qwraps2::mean_sd(myData$wellness, na_rm = TRUE),
        "min" = ~min(myData$wellness, na.rm = TRUE),
        "max" = ~max(myData$wellness, na.rm = TRUE)
      ),
    
    "Happiness" =
      list(
        "Happiness" = ~qwraps2::n_perc(myData$RU_happy)

      )
  )



how the table looks like:

|Summary Statistics Table for the Wellness Data Set |myData$city: Eilat (N = 25) |myData$city: jerusalem (N = 25) |myData$city: Metula (N = 25) |myData$city: TelAviv (N = 25) |
|:--------------------------------------------------|:---------------------------|:-------------------------------|:----------------------------|:-----------------------------|
|**Hobby(hours/week)**                              |&nbsp;&nbsp;                |&nbsp;&nbsp;                    |&nbsp;&nbsp;                 |&nbsp;&nbsp;                  |
|&nbsp;&nbsp; mean (sd)                             |15.54 &plusmn; 4.49         |15.54 &plusmn; 4.49             |15.54 &plusmn; 4.49          |15.54 &plusmn; 4.49           |
|&nbsp;&nbsp; min                                   |3.926501                    |3.926501                        |3.926501                     |3.926501                      |
|&nbsp;&nbsp; max                                   |27.00809                    |27.00809                        |27.00809                     |27.00809                      |
|**Work(hours/week)**                               |&nbsp;&nbsp;                |&nbsp;&nbsp;                    |&nbsp;&nbsp;                 |&nbsp;&nbsp;                  |
|&nbsp;&nbsp; mean (sd)                             |30.45 &plusmn; 19.51        |30.45 &plusmn; 19.51            |30.45 &plusmn; 19.51         |30.45 &plusmn; 19.51          |
|&nbsp;&nbsp; min                                   |1.945099                    |1.945099                        |1.945099                     |1.945099                      |
|&nbsp;&nbsp; max                                   |68.70944                    |68.70944                        |68.70944                     |68.70944                      |
|**Wellness**                                       |&nbsp;&nbsp;                |&nbsp;&nbsp;                    |&nbsp;&nbsp;                 |&nbsp;&nbsp;                  |
|&nbsp;&nbsp; mean (sd)                             |-56.11 &plusmn; 100.01      |-56.11 &plusmn; 100.01          |-56.11 &plusmn; 100.01       |-56.11 &plusmn; 100.01        |
|&nbsp;&nbsp; min                                   |-259.3496                   |-259.3496                       |-259.3496                    |-259.3496                     |
|&nbsp;&nbsp; max                                   |144.8053                    |144.8053                        |144.8053                     |144.8053                      |
|**Happiness**                                      |&nbsp;&nbsp;                |&nbsp;&nbsp;                    |&nbsp;&nbsp;                 |&nbsp;&nbsp;                  |
|&nbsp;&nbsp; Happiness                             |35 (35.00%)                 |35 (35.00%)                     |35 (35.00%)                  |35 (35.00%)                   |

Solution

  • So you have to actually render the Markdown to get the graphical output you wanted.

    I copied the Markdown your R command spit out into a new R Markdown file. After escaping the dollar signs ($ to \$) due to how RStudio's knit function works, when I knit, I get the following table:

    enter image description here