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)

Arguments

data

A data frame that must contain at least two columns:

  • stat_0: A column whose missing (NA) values are to be replaced.

  • n: A column providing replacement values for stat_0 when its values are missing.

Value

A modified data frame with:

  • Updated stat_0 values (replaced with n values where NA is found).

  • The n column removed after integration.

Details

  • 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.

Examples

# 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