Simplify and fix summary stats

Tento commit je obsažen v:
2024-09-16 21:14:59 -04:00
rodič d5141d04c4
revize 39331eacc2

Zobrazit soubor

@@ -156,7 +156,7 @@ update_gene_names <- function(df, sgd_gene_list) {
}
calculate_summary_stats <- function(df, variables, group_vars = c("OrfRep", "conc_num", "conc_num_factor")) {
# Summarize the variables within the grouped data
summary_stats <- df %>%
group_by(across(all_of(group_vars))) %>%
summarise(
@@ -172,11 +172,10 @@ calculate_summary_stats <- function(df, variables, group_vars = c("OrfRep", "con
)
# Create a cleaned version of df that doesn't overlap with summary_stats
cols_to_exclude <- unique(c(variables, group_vars))
cols_to_keep <- setdiff(names(df), names(summary_stats)[-which(names(summary_stats) %in% group_vars)])
df_cleaned <- df %>%
select(-any_of(cols_to_exclude))
select(all_of(cols_to_keep))
# Join the stats back to the original dataframe
df_with_stats <- left_join(df_cleaned, summary_stats, by = group_vars)
return(list(summary_stats = summary_stats, df_with_stats = df_with_stats))