I have a table with the mean of the variable (budget) over the groups (size and strictness) and the p-value of the Kruskall-Wallis test between budget and strictness (apart for every size group, so not comparing sizes here). I make the code separately and than combine everything in Excel as I do not know how to adjust the code to get is automatically. Every time I make a change in the data I have to make the table again. And also I have more variables for which I need to do this which takes up a lot of time.

I have the following code:

```
small2017 <- subset(total2017, size=="Small")
medium2017 <- subset(total2017, size=="Medium")
large2017 <- subset(total2017, size=="Large")

library(dplyr)

total2017 %>% group_by(size, strictness) %>%
summarise(mean=mean(budget, na.rm=TRUE), sd=sd(budget, na.rm=TRUE), n=n()) %>%
filter(!is.na(strictness))

Kruskal.test(budget ~ strictness, data=small2017)
Kruskal.test(budget ~ strictness, data=medium2017)
Kruskal.test(budget ~ strictness, data=large2017)

```

I made this in excel and copied it to latex.
[![enter image description here](https://i.stack.imgur.com/hfTLj.png)](https://i.stack.imgur.com/hfTLj.png)

You can find an example of my data below:

```r

example <- tibble::tribble(

     ~size,     ~budget, ~strictness,

   "Small", "11,718183",          1L,

  "Medium",  "5,264815",          2L,

   "Large",  "-0,43848",          NA,

   "Small",  "0,658158",          2L,

  "Medium",   "-1,2867",          3L,

   "Large",   "-0,8482",          2L,

   "Small",  "4,584138",          1L,

  "Medium",   "7,26868",          1L,

   "Large",   "-7,1868",          NA,

   "Small",  "8,186884",          1L,

  "Medium",   "16,1548",          NA,

   "Large",  "1,516844",          2L,

   "Small",   "-5,1687",          2L,

  "Medium",  "11,15687",          2L,

   "Large",   "-4,1867",          3L,

   "Small",   "7,25687",          3L,

  "Medium", "5,1682186",          1L,

   "Large", "-6,186515",          2L,

   "Small",    "7,2687",          3L

  )

head(example)

#> # A tibble: 6 x 3

#>   size   budget    strictness

#>   <chr>  <chr>          <int>

#> 1 Small  11,718183          1

#> 2 Medium 5,264815           2

#> 3 Large  -0,43848          NA

#> 4 Small  0,658158           2

#> 5 Medium -1,2867            3

#> 6 Large  -0,8482            2

```

Created on 2020-04-30 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)