Skip to contents

Takes a dataframe and bins the values of the specified column into three categories: less than 30, between 30 and 45 inclusive, and greater than 45. These bins are then encoded as 0, 1, and 2, respectively. Missing values are left as NA.

Usage

add_hrctv_volume_bins(df)

Arguments

df

A dataframe containing the volume column to be binned.

Value

A dataframe with the original data and a new column 'fraction01hrctv_volume_bins' with encoded values.

Examples

# Example usage:
library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
sample_df <- data.frame(fraction01hrctv_volume_tdvh = c(10, 35, 50, 22, 40, NA))
binned_df <- add_hrctv_volume_bins(sample_df)
print(binned_df)
#>   fraction01hrctv_volume_tdvh fraction01hrctv_volume_bins
#> 1                          10                           0
#> 2                          35                           1
#> 3                          50                           2
#> 4                          22                           0
#> 5                          40                           1
#> 6                          NA                          NA