I am attempting to use the new Dplyr scoped summarize() verbs to search through my data table and create a summary dataframe, grouped by treatment arm, for each one of a set of multiple outcomes that contains statistics for both numeric (2.5th, 50th, 97.5th percentiles) & categorical predictor variables (counts). I appear to have been successful with these computations (thanks to this massively helpful post - r summarize_if with multiple conditions).
However my dataframes are not visually friendly, as the quantile() & table() functions insert lists into each dataframe cell so I am unable to scroll through the dataframe within the R-Studio viewer to browse through the results. Does anybody have any suggestions regarding how to reorganize or view this dataframe in R-Studio in order to see the full results of these lists more clearly?
Thank you kindly!
outcome.dfs <- list()
dt <- data.table(short.vars.full) # convert to data table to allow for subsetting with column name stored in variable
for (ae.outcome in outcomes.list) {
outcome.dfs[[ae.outcome]] <- dt[get(ae.outcome) == ae.outcome, ] %>%
select(-USUBJID) %>%
group_by(XDARM) %>%
summarise_all(~ if(is.numeric(.))
list(format(round(quantile(., probs = c(.025,0.50,0.975), na.rm = TRUE), 2), nsmall=2))
else if (is.factor(.))
list(table(.)))
}