Skip to contents

This function processes a dataframe to convert density values that might be in various representations (e.g., "10K", "10k") into their real number equivalents. For instance, "10K" or "10k" will be converted to 10000.

Usage

convert_density_representations(user_data, density_col)

Arguments

user_data

A dataframe containing user data with density values.

density_col

A string specifying the column name of the density values in user_data.

Value

A dataframe with the converted density values. Special values are 0 ('Negative Control') and -1 ('Value was not known'). All other values are returned as numerics. In cases where 'K' or 'k' is appended, the numeric value in front is multiplied by 1000.

Details

If the density value is "neg" or "unk", it will be converted to 0 and -1, respectively.

Examples

user_df <- data.frame(Density = c("1", "10k", "100K"))
convert_density_representations(user_df, "Density")
#>   Density
#> 1   1e+00
#> 2   1e+04
#> 3   1e+05