-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with rbind
when using different dataset (it works when using same data.frame)
#828
Comments
Hi, @Melkiades , |
Not directly. Lets say that usually we use rbind when we do not how to create a table, but ideally it should be used only when the tables contain different data. For example, second issue can be solved w/ tbl <- basic_table() %>%
# build_table(mtcars)
# tbl2 <- basic_table() %>%
split_rows_by("vs") %>%
analyze("cyl") %>%
build_table(mtcars %>% mutate(vs = factor(vs))) In general keep in mind to use |
hi @superliqianqian1 , please consider the following code > basic_table() %>%
+ split_cols_by(var = "ARM") %>%
+ split_rows_by(var = "STRATA1") %>%
+ tern::summarize_num_patients(
+ var = "ID", .stats = ("unique")
+ ) %>%
+ build_table( DM_modify)
|
Thanks for the reply. but the percentage of .stats = ("unique") differ with my final result. I just provide a simple example for your checking purpose. The real case of my table need more flexible denominators than denominators of tern::summarize_num_patients() , so this is the main reason of need combining results from different build_table(df, alt_counts_df ). But rbind does not work. I think some information kept in final tables, so rbind refuse to bind. But I do not know to to remove such extra information. |
Hi, @Melkiades @shajoezhu , When I combined those 2 tables together, there is an error. I know there may be some limitations when we use rbind function to combine 2 tables. I'm not very familiar to use tern and rtables packages. Do you have any suggestions to generate this special table? Thank you very much. library(random.cdisc.data)
library(dplyr)
library(rtables)
library(haven)
library(purrr)
library(stringr)
library(tern)
library(forcats)
library(formatters)
adsl_cdisc1 <- random.cdisc.data::cadsl
adex_cdisc1 <- random.cdisc.data::cadex
adsl_cdisc2 <- dplyr::filter(adsl_cdisc1, SAFFL == "Y") |>
dplyr::select(USUBJID, TRT01A) |>
dplyr::mutate(
TRT01A = forcats::fct_inorder(TRT01A)
)
adex_cdisc2 <- dplyr::select(
adex_cdisc1, USUBJID, SAFFL, STRATA1, AVISIT) |>
dplyr::left_join(adsl_cdisc2, by = "USUBJID") |>
dplyr::mutate(
EXP = dplyr::case_when(
!is.na(AVISIT) ~ "Number of exposed participants",
TRUE ~ NA_character_
),
STRA = dplyr::case_when(
STRATA1 == "B" ~ "Number of records with STRATA1 = B by visit",
TRUE ~ NA_character_
),
SORT = paste(USUBJID, AVISIT)
) |>
dplyr::filter(SAFFL == "Y", !is.na(AVISIT))
adex_cdisc3 <- dplyr::filter(adex_cdisc1, SAFFL == "Y") |>
dplyr::select(USUBJID, AVISIT) |>
dplyr::right_join(adsl_cdisc2, by = "USUBJID") |>
dplyr::mutate(
SORT = paste(USUBJID, AVISIT)
) |>
distinct(SORT, TRT01A)
tbl_recipe1 <- basic_table() |>
add_colcounts() |>
split_cols_by("TRT01A") |>
count_occurrences("EXP",
id = "USUBJID",
.stats = "count_fraction"
) |>
rtables::build_table(adex_cdisc2, alt_counts_df = adsl_cdisc2)
tbl_recipe2 <- basic_table() |>
add_colcounts() |>
split_cols_by("TRT01A") |>
count_occurrences("STRA",
id = "SORT",
.stats = "count_fraction"
) |>
rtables::build_table(adex_cdisc2, alt_counts_df = adex_cdisc3)
tbl <- rbind(
tbl_recipe1,
rtables::rrow(""),
tbl_recipe2
)
```r |
hi @lanlanlaura , can I suggest we move the discussion for this topic to StackOverflow, https://stackoverflow.com/questions/tagged/nest-rtables, you can create a new topic there, and we can follow-up there . We are trying to build a user community to support each other in the future. thanks you |
hi, @shajoezhu , I post this topic to StackOverflow with tag [nest-rtables] and it's in process of pending review. Thank you. |
Created on 2024-02-22 with reprex v2.1.0
Similarly:
Created on 2024-02-22 with reprex v2.1.0
The text was updated successfully, but these errors were encountered: