I need to make a loop where in each round a specific variable is filtered and then a table of another variable is calculated and that is exported to an excel sheet. How can it be done?

For example, I have this database:

```
> # A tibble: 15 x 4
> var1 var2 var3 values
> <lgl> <lgl> <lgl> <chr>
> 1 TRUE TRUE TRUE car
> 2 TRUE TRUE FALSE bike
> 3 TRUE FALSE TRUE moto
> 4 TRUE FALSE FALSE car
> 5 TRUE TRUE FALSE car
> 6 TRUE FALSE TRUE car
> 7 TRUE FALSE TRUE car
> 8 FALSE TRUE FALSE car
> 9 TRUE FALSE FALSE moto
> 10 TRUE TRUE FALSE car
> 11 TRUE FALSE FALSE bike
> 12 TRUE TRUE TRUE car
> 13 FALSE TRUE FALSE moto
> 14 TRUE FALSE TRUE car
> 15 FALSE TRUE TRUE car
```

and I would like to make a table of values when var1 is TRUE, another when var2 is TRUE and another when var3 is TRUE and export each table in a separate sheet. Individually I would do this:

```
df %>%
filter(var1) %>%
count(values) %>%
arrange(-n) %>%
mutate(p= round(n/sum(n),2)) %>%
openxlsx::write.xlsx("R/test/tables.xlsx", sheetName="Table1")
df %>%
filter(var2) %>%
count(values) %>%
arrange(-n) %>%
mutate(p= round(n/sum(n),2)) %>%
xlsx::write.xlsx("R/test/tables.xlsx", sheetName="Table2", append = T)
df %>%
filter(var3) %>%
count(values) %>%
arrange(-n) %>%
mutate(p= round(n/sum(n),2)) %>%
xlsx::write.xlsx("R/test/tables.xlsx", sheetName="Table3", append = T)
```

but I would like to be able to do it in a loop