View source: R/derived_variables.R
append_rowwise_summary_indicator | R Documentation |
Low level function that appends a (binary) indicator column to a dataframe, summarising rowwise whether any values in a selection of existing columns match one or more specified values.
append_rowwise_summary_indicator( df, cols, yes_values, new_indicator_colname, new_indicator_var_label, new_indicator_yes_value = "Yes", new_indicator_no_value = "No" )
df |
Data frame |
cols |
Character vector of columns to summarise |
yes_values |
Vector. |
new_indicator_colname |
Name of new indicator column. |
new_indicator_var_label |
Character string to set as variable label for new indicator column. |
new_indicator_yes_value |
Default is "Yes". |
new_indicator_no_value |
Default is "No" |
A data frame with an additional column, named as per
new_indicator_colname
.
# example input df df <- tibble::tribble( ~med_1, ~med_2, ~med_3, ~IGNORED_COL, "Beta blocker", NA, NA, "Beta blocker", "ACE inhibitor", "Beta blocker", NA, "Beta blocker", "Aspirin", "Aspirin", NA, "Beta blocker", "Aspirin", "ACE inhibitor", NA, "Beta blocker" ) # add indicator col df <- append_rowwise_summary_indicator(df = df, cols = c("med_1", "med_2", "med_3"), yes_values = c("Beta blocker", "ACE inhibitor"), new_indicator_colname = "on_anti_hypertensive", new_indicator_var_label = "Taking anti-hypertensive medication", new_indicator_yes_value = "Yes", new_indicator_no_value = "No") # print result print(df) # print variable label for new column print(attributes(df$on_anti_hypertensive)$label)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.