Closed SuzanneSegerstrom closed 9 months ago
Hi Suzanne,
I think there are bugs in your R code unrelated to papaja
. Also, you need to use cat()
rather than print()
. The following works for me:
```{r test, results = "asis"}
library("magrittr")
data <- cars
################### write a function to do all tables ####################################
### get the variable names
cat_vars <- data %>% colnames() %>% as.vector()
### put my syntax inside a function
cat_table <- function(x) {
freq <- table(data[, x]) %>% t() %>% round(., digits = 0)
perc <- prop.table(freq) %>% t() %>% round(., digits = 2) %>% as.vector()
table_cat <-
rbind(freq,perc) %>% as.data.frame() %>% set_rownames(c("Frequency", "Proportion"))
}
### get the "raw" data to make into tables
categorical <- lapply(cat_vars, cat_table)
for (i in 1:length(cat_vars)) {
cat(papaja::apa_table(categorical[[i]], caption = "test"))
}
```
Given that this seems to be unrelated to papaja
, I'll close this issue. If you have further questions, StackOverflow would be a more suitable platform to get answers quickly. You can use the papaja
tag over there for anything related to this package.
Cheers.
I have a lot of tables to create for a data dictionary, and I've figured out how to make them look like what I want using papaja. However, it would be great if I could use a loop to ,create the multiple tables.
I've tried using different versions of apply and putting apa_table inside and outside the loop, but nothing is rendering correctly. I have tried pdf, word, and html. Sorry if I'm missing something obvious! Example syntax below. I am using ```{r echo=FALSE, results = 'asis', include = TRUE} in the block.
A simple example:
Result in knit document:
result in knit document: