Post

DP07 Joining two Tables - Left Join

Description

This script provides an example of working with relational data tables and demonstrates a method for imputing values. Unlike previous cases where data was hardcoded within the script, this example involves importing a table containing data to be updated, such as practices type: Family, Pediatric, etc. Imputation of values is achieved using the left_join function.

R Script - Join two Tables

Data: List of Patients and Practices. View of first 10 from a list of 3000.

07 Results List of Patients and Practices

List of Practices and Type.

07 Results List of Practices and Type

Code: Left_join Two Tables. Common key: ‘Practice.Name’

1
2
PPL_df <- PPL_df %>% left_join(practices_type, 
              by = c('Practice_Name' = 'Practice.Name'))

Final result. Recap of Patients by Type of Practice.

1
2
PPL_df %>% dplyr::group_by(Practice.Type) %>% 
                        tally() %>% arrange(desc(n))

Results.

07 Results Recap of Patients by Practice Type

__

End of Post

This post is licensed under CC BY 4.0 by the author.