col_cal_percent {dataMojo} | R Documentation |
create a new column which is the percentage of other columns
Description
create a new column which is the percentage of other columns
Usage
col_cal_percent(df, new_col_name, numerator_cols, denominator_cols)
Arguments
df |
input data frame |
new_col_name |
new column name |
numerator_cols |
numerator columns |
denominator_cols |
denominator columns |
Value
data frame with a new percentage column
Examples
test_df <- data.frame(
hc1 = c(2, 0, 1, 5, 6, 7, 10),
hc2 = c(1, 0, 10, 12, 4, 1, 9 ),
total = c(10, 2, 0, 39, 23, 27, 30)
)
dataMojo::col_cal_percent(test_df,
new_col_name = "hc_percentage",
numerator_cols = c("hc1", "hc2"),
denominator_cols = "total"
)
[Package dataMojo version 1.0.0 Index]