This function modifies a data frame by updating the stat_0 column. If any values in
stat_0 are missing (NA), they are replaced by the values from the n column.
After the replacement, the n column is removed from the data frame.
customize_table_body(data)A modified data frame with:
Updated stat_0 values (replaced with n values where NA is found).
The n column removed after integration.
The function uses dplyr::case_when to conditionally update the stat_0 column.
After the replacement process, the n column is dropped using dplyr::select(-n).
This function is particularly useful for cleaning and preparing table data.
# Example data
data <- data.frame(
stat_0 = c(NA, "B", "C"),
n = c(10, 20, 30)
)
# Apply the function
modified_data <- customize_table_body(data)
print(modified_data)
#> stat_0
#> 1 10
#> 2 B
#> 3 C