Learn R Programming

healthyR (version 0.2.0)

kmeans_user_item_tbl: K-Means Functions

Description

Takes in a data.frame/tibble and transforms it into an aggregated/normalized user-item tibble of proportions. The user will need to input the parameters for the rows/user and the columns/items.

Usage

kmeans_user_item_tbl(.data, .row_input, .col_input, .record_input)

Value

A aggregated/normalized user item tibble

Arguments

.data

The data that you want to transform

.row_input

The column that is going to be the row (user)

.col_input

The column that is going to be the column (item)

.record_input

The column that is going to be summed up for the aggregattion and normalization process.

Author

Steven P. Sanderson II, MPH

Details

This function should be used before using a k-mean model. This is commonly referred to as a user item matrix because "users" tend to be on the rows and "items" (e.g. orders) on the columns. You must supply a column that can be summed for the aggregation and normalization process to occur.

Examples

Run this code
library(healthyR.data)
library(dplyr)

data_tbl <- healthyR_data%>%
   filter(ip_op_flag == "I") %>%
   filter(payer_grouping != "Medicare B") %>%
   filter(payer_grouping != "?") %>%
   select(service_line, payer_grouping) %>%
   mutate(record = 1) %>%
   as_tibble()

 kmeans_user_item_tbl(
   .data           = data_tbl
   , .row_input    = service_line
   , .col_input    =  payer_grouping
   , .record_input = record
 )

Run the code above in your browser using DataLab