Learn R Programming

healthyR (version 0.2.0)

kmeans_tidy_tbl: K-Means tidy Functions

Description

K-Means tidy functions

Usage

kmeans_tidy_tbl(.kmeans_obj, .data, .tidy_type = "tidy")

Value

A tibble

Arguments

.kmeans_obj

A stats::kmeans() object

.data

The user item tibble created from kmeans_user_item_tbl()

.tidy_type

"tidy","glance", or "augment"

Author

Steven P. Sanderson II, MPH

Details

Takes in a k-means object and its associated user item tibble and then returns one of the items asked for. Either: broom::tidy(), broom::glance() or broom::augment(). The function defaults to broom::tidy().

Examples

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

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()

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

 km_obj  <- kmeans_obj(uit_tbl)

 kmeans_tidy_tbl(
   .kmeans_obj  = km_obj
   , .data      = uit_tbl
   , .tidy_type = "augment"
 )

 kmeans_tidy_tbl(
   .kmeans_obj  = km_obj
   , .data      = uit_tbl
   , .tidy_type = "glance"
 )

 kmeans_tidy_tbl(
   .kmeans_obj  = km_obj
   , .data      = uit_tbl
   , .tidy_type = "tidy"
 ) %>%
   glimpse()

Run the code above in your browser using DataLab