for (i in c(1,99)) {
filtered_base <-
base %>%
filter(triaje_anormal== i)
for (j in c("Anormales Grado I (menor)",
"Anormales Grado II (mayor)",
"Anormales No específico",
"Hallazgos normales",
"Hallazgos varios",
"NO",
"Sospecha de invasión") {
filtered_base %>%
filter(colpo_result_1== j) %>%
select(biopsia_result_1 ) %>%
tbl_summary()
}
}
It doesn't work because you overwrite filtered_base, but it's also unnecessary:
library(tidyverse)
library(gtsummary)
base %>% filter(triaje_anormal %in% c(1, 99)) %>%
filter(colpo_result_1 %in% c("Anormales Grado I (menor)",
"Anormales Grado II (mayor)",
"Anormales No específico",
"Hallazgos normales",
"Hallazgos varios",
"NO",
"Sospecha de invasión")) %>%
select(biopsia_result_1) %>%
tbl_summary()
Hi, these is not what I need. I need 14 tables, 7 of biopsia_result1 filter for each value of colpo_result_1 and filter by triaje_anormal=1 and 7 of biospia_result1 filter for each value of colpo_result1 and filter by triaje_anormal=99
base_list <- base %>%
# filter only 1 or 99
filter(triaje_anormal %in% c(1, 99)) %>%
# make a list of two dataframes, one for triaje_anormal = 1 and the other for triaje_anormal = 99
group_split(.by = triaje_anormal) %>%
# group_split() every dataframe on baseList by colpo_result_1
map(\(x) group_split(x, .by = colpo_result_1))
and then you can access each of the 14 dataframes as (for example)
This is a sign of a syntax error; in your case an unmatched open parenthesis in your second for loop.
However, fixing the syntax error won't make the tables visible since you're only creating them — and not printing them — inside a for loop. To see them, add print() after tbl_summary():
Thanks! And after that how can I make the tables?
I try this and it doesn't work.
base_list <-
base %>%
# filter only 1 or 99
filter(triaje_anormal %in% c(1, 99)) %>%
# make a list of two dataframes, one for triaje_anormal = 1 and the other for triaje_anormal = 99
group_split(.by = triaje_anormal) %>%
# group_split() every dataframe on baseList by colpo_result_1
map(\(x) group_split(x, .by = colpo_result_1)) %>%
select(biopsia_result_1 ) %>%
tbl_summary()
Error in `select()`:
! `select()` doesn't handle lists.
Run `rlang::last_trace()` to see where the error occurred.