Analysis Of Patient Data

Objectives

The objective is to create dynamic reports using R Marksdown and generate the output in an HTML document.

Probem Definition

To learn how to manipulate a given dataset using the package dplyr

Code & Output

knitr Global Options

# for development
knitr::opts_chunk$set(echo=TRUE, eval=TRUE, error=TRUE, warning=TRUE, message=TRUE, cache=FALSE, tidy=FALSE, fig.path='figures/')
# for production
#knitr::opts_chunk$set(echo=TRUE, eval=TRUE, error=FALSE, warning=FALSE, message=FALSE, cache=FALSE, tidy=FALSE, fig.path='figures/')

Load Libraries

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

Read Data

dfr <- read.csv("./data/patient-data.csv", header=T, stringsAsFactors=F)
head(dfr)
##          ID      Name  Race Gender Smokes HeightInCms WeightInKgs
## 1 AC/AH/001 Demetrius White   Male  False      182.87       76.57
## 2 AC/AH/017   Rosario White   Male  False      179.12       80.43
## 3 AC/AH/020     Julio Black   Male  False      169.15       75.48
## 4 AC/AH/022      Lupe White   Male  False      175.66       94.54
## 5 AC/AH/029    Lavern White Female  False      164.47       71.78
## 6 AC/AH/033    Bernie   Dog Female   True      158.27       69.90
##    BirthDate        State  Pet HealthGrade  Died RecordDate
## 1 31-01-1972  Georgia,xxx  Dog           2 False 25-11-2015
## 2 09-06-1972     Missouri  Dog           2 False 25-11-2015
## 3 03-07-1972 Pennsylvania None           2 False 25-11-2015
## 4 11-08-1972      Florida  Cat           1 False 25-11-2015
## 5 06-06-1973         Iowa NULL           2  True 25-11-2015
## 6 25-06-1973     Maryland  Dog           2 False 25-11-2015

Adding new column BMIValue

dfr <- mutate(dfr,BMIValue=(WeightInKgs*(10^4)/(HeightInCms)^2))
head(dfr)
##          ID      Name  Race Gender Smokes HeightInCms WeightInKgs
## 1 AC/AH/001 Demetrius White   Male  False      182.87       76.57
## 2 AC/AH/017   Rosario White   Male  False      179.12       80.43
## 3 AC/AH/020     Julio Black   Male  False      169.15       75.48
## 4 AC/AH/022      Lupe White   Male  False      175.66       94.54
## 5 AC/AH/029    Lavern White Female  False      164.47       71.78
## 6 AC/AH/033    Bernie   Dog Female   True      158.27       69.90
##    BirthDate        State  Pet HealthGrade  Died RecordDate BMIValue
## 1 31-01-1972  Georgia,xxx  Dog           2 False 25-11-2015 22.89674
## 2 09-06-1972     Missouri  Dog           2 False 25-11-2015 25.06859
## 3 03-07-1972 Pennsylvania None           2 False 25-11-2015 26.38080
## 4 11-08-1972      Florida  Cat           1 False 25-11-2015 30.63867
## 5 06-06-1973         Iowa NULL           2  True 25-11-2015 26.53567
## 6 25-06-1973     Maryland  Dog           2 False 25-11-2015 27.90487

Adding new column BMILabel

dfr <- mutate(dfr, BMILabel= ifelse(BMIValue < 18.5,"Underweight",
ifelse(BMIValue > 18.5 & BMIValue < 25, "Normal",
                                        ifelse(BMIValue > 25 & BMIValue < 30, "Overweight",
                                                  ifelse(BMIValue > 30, "Obese",NA)))))
head(dfr)
##          ID      Name  Race Gender Smokes HeightInCms WeightInKgs
## 1 AC/AH/001 Demetrius White   Male  False      182.87       76.57
## 2 AC/AH/017   Rosario White   Male  False      179.12       80.43
## 3 AC/AH/020     Julio Black   Male  False      169.15       75.48
## 4 AC/AH/022      Lupe White   Male  False      175.66       94.54
## 5 AC/AH/029    Lavern White Female  False      164.47       71.78
## 6 AC/AH/033    Bernie   Dog Female   True      158.27       69.90
##    BirthDate        State  Pet HealthGrade  Died RecordDate BMIValue
## 1 31-01-1972  Georgia,xxx  Dog           2 False 25-11-2015 22.89674
## 2 09-06-1972     Missouri  Dog           2 False 25-11-2015 25.06859
## 3 03-07-1972 Pennsylvania None           2 False 25-11-2015 26.38080
## 4 11-08-1972      Florida  Cat           1 False 25-11-2015 30.63867
## 5 06-06-1973         Iowa NULL           2  True 25-11-2015 26.53567
## 6 25-06-1973     Maryland  Dog           2 False 25-11-2015 27.90487
##     BMILabel
## 1     Normal
## 2 Overweight
## 3 Overweight
## 4      Obese
## 5 Overweight
## 6 Overweight

Data Cleaning

# converting yes or no to true or false
dfr$Smokes <- gsub("Yes","True", gsub("No","False", dfr$Smokes))
# converting null to none
dfr$Pet <- gsub("NULL","None", dfr$Pet)
# removing white spaces
dfr$Gender <- trimws(dfr$Gender)
# removing extra characters
dfr$State[dfr$State=="Georgia,xxx"] <- "Georgia"
# converting wrong values to invalid
dfr$Race <- ifelse(!dfr$Race=="White" & !dfr$Race=="Black" & !dfr$Race=="Hispanic" & !dfr$Race=="Asian" & 
               !dfr$Race=="Bi-Racial", NA, dfr$Race)
head(dfr)
##          ID      Name  Race Gender Smokes HeightInCms WeightInKgs
## 1 AC/AH/001 Demetrius White   Male  False      182.87       76.57
## 2 AC/AH/017   Rosario White   Male  False      179.12       80.43
## 3 AC/AH/020     Julio Black   Male  False      169.15       75.48
## 4 AC/AH/022      Lupe White   Male  False      175.66       94.54
## 5 AC/AH/029    Lavern White Female  False      164.47       71.78
## 6 AC/AH/033    Bernie  <NA> Female   True      158.27       69.90
##    BirthDate        State  Pet HealthGrade  Died RecordDate BMIValue
## 1 31-01-1972      Georgia  Dog           2 False 25-11-2015 22.89674
## 2 09-06-1972     Missouri  Dog           2 False 25-11-2015 25.06859
## 3 03-07-1972 Pennsylvania None           2 False 25-11-2015 26.38080
## 4 11-08-1972      Florida  Cat           1 False 25-11-2015 30.63867
## 5 06-06-1973         Iowa None           2  True 25-11-2015 26.53567
## 6 25-06-1973     Maryland  Dog           2 False 25-11-2015 27.90487
##     BMILabel
## 1     Normal
## 2 Overweight
## 3 Overweight
## 4      Obese
## 5 Overweight
## 6 Overweight

Convert Health Grade

dfr$HealthGrade <- ifelse(dfr$HealthGrade==1,"Good Heath", 
                          ifelse(dfr$HealthGrade==2, "Normal", 
                                 ifelse(dfr$HealthGrade==3,"Bad Health",NA)))
head(dfr)
##          ID      Name  Race Gender Smokes HeightInCms WeightInKgs
## 1 AC/AH/001 Demetrius White   Male  False      182.87       76.57
## 2 AC/AH/017   Rosario White   Male  False      179.12       80.43
## 3 AC/AH/020     Julio Black   Male  False      169.15       75.48
## 4 AC/AH/022      Lupe White   Male  False      175.66       94.54
## 5 AC/AH/029    Lavern White Female  False      164.47       71.78
## 6 AC/AH/033    Bernie  <NA> Female   True      158.27       69.90
##    BirthDate        State  Pet HealthGrade  Died RecordDate BMIValue
## 1 31-01-1972      Georgia  Dog      Normal False 25-11-2015 22.89674
## 2 09-06-1972     Missouri  Dog      Normal False 25-11-2015 25.06859
## 3 03-07-1972 Pennsylvania None      Normal False 25-11-2015 26.38080
## 4 11-08-1972      Florida  Cat  Good Heath False 25-11-2015 30.63867
## 5 06-06-1973         Iowa None      Normal  True 25-11-2015 26.53567
## 6 25-06-1973     Maryland  Dog      Normal False 25-11-2015 27.90487
##     BMILabel
## 1     Normal
## 2 Overweight
## 3 Overweight
## 4      Obese
## 5 Overweight
## 6 Overweight

Display top 10 records on BMIValue

dfr <- arrange(dfr, desc(BMIValue))
head(dfr, 10)
##           ID     Name  Race Gender Smokes HeightInCms WeightInKgs
## 1  AC/SG/009    Sammy White   Male  False      166.84       88.25
## 2  AC/SG/064      Jon White   Male  False      169.16       90.08
## 3  AC/AH/076   Albert White   Male  False      176.22       97.67
## 4  AC/AH/104   Jeremy White   Male   True      169.85       90.63
## 5  AC/AH/022     Lupe White   Male  False      175.66       94.54
## 6  AC/AH/248   Andrea White   Male  False      178.64       97.05
## 7  AC/SG/067   Thomas White   Male  False      167.51       84.15
## 8  AC/AH/052 Courtney White   Male   True      175.39       92.22
## 9  AC/AH/159   Edward White   Male  False      181.64       96.91
## 10 AC/AH/127     Jame White   Male  False      167.75       82.06
##     BirthDate        State  Pet HealthGrade  Died RecordDate BMIValue
## 1  04-03-1972      Vermont  Dog  Good Heath False 25-06-2016 31.70402
## 2  04-10-1972     Illinois  Cat      Normal  True 25-07-2016 31.47988
## 3  08-04-1973    Louisiana  Cat      Normal False 25-12-2015 31.45218
## 4  12-04-1972     Kentucky None  Good Heath  True 25-12-2015 31.41528
## 5  11-08-1972      Florida  Cat  Good Heath False 25-11-2015 30.63867
## 6  12-01-1973      Indiana  Cat  Good Heath  True 25-05-2016 30.41152
## 7  19-07-1972 Pennsylvania Bird      Normal  True 25-07-2016 29.98974
## 8  16-03-1972      Indiana Bird  Bad Health False 25-12-2015 29.97888
## 9  04-12-1972  Connecticut  Cat      Normal False 25-02-2016 29.37282
## 10 29-10-1972        Texas  Dog  Good Heath  True 25-01-2016 29.16127
##      BMILabel
## 1       Obese
## 2       Obese
## 3       Obese
## 4       Obese
## 5       Obese
## 6       Obese
## 7  Overweight
## 8  Overweight
## 9  Overweight
## 10 Overweight

Display bottom 10 records on BMIValue

dfr <- arrange(dfr, BMIValue)
head(dfr, 10)
##           ID      Name     Race Gender Smokes HeightInCms WeightInKgs
## 1  AC/SG/193    Ronnie    White   Male   True      185.43       73.63
## 2  AC/AH/061    Lester    Black   Male  False      181.13       72.33
## 3  AC/SG/099    Leslie    Asian   Male  False      172.72       67.62
## 4  AC/AH/001 Demetrius    White   Male  False      182.87       76.57
## 5  AC/AH/210     Keith Hispanic Female   True      170.03       66.68
## 6  AC/AH/086      Kyle    Black   Male   True      180.11       75.72
## 7  AC/AH/045   Shirley    White   Male  False      181.32       76.90
## 8  AC/AH/089      Dong    White   Male  False      179.24       75.54
## 9  AC/AH/164     Shane Hispanic   Male   True      177.03       74.04
## 10 AC/AH/114      Kris Hispanic   Male  False      177.75       74.84
##     BirthDate        State  Pet HealthGrade  Died RecordDate BMIValue
## 1  05-06-1973         Iowa  Dog  Bad Health False 25-09-2016 21.41385
## 2  16-11-1972    Wisconsin  Dog        <NA>  True 25-12-2015 22.04640
## 3  04-02-1972         Ohio  Cat  Good Heath False 25-07-2016 22.66678
## 4  31-01-1972      Georgia  Dog      Normal False 25-11-2015 22.89674
## 5  28-08-1972     New York  Dog        <NA> False 25-03-2016 23.06452
## 6  12-05-1973      Georgia  Cat  Bad Health False 25-12-2015 23.34183
## 7  25-12-1971    Louisiana  Dog  Good Heath False 25-11-2015 23.39025
## 8  11-03-1972   California None      Normal  True 25-12-2015 23.51295
## 9  18-02-1972      Florida None      Normal False 25-02-2016 23.62505
## 10 19-11-1972 Pennsylvania Bird  Bad Health False 25-01-2016 23.68725
##    BMILabel
## 1    Normal
## 2    Normal
## 3    Normal
## 4    Normal
## 5    Normal
## 6    Normal
## 7    Normal
## 8    Normal
## 9    Normal
## 10   Normal

Display Frequency of Gender > Race

summarise(group_by(dfr, Gender, Race), n())
## Source: local data frame [10 x 3]
## Groups: Gender [?]
## 
##    Gender      Race `n()`
##     <chr>     <chr> <int>
## 1  Female     Asian     3
## 2  Female     Black     3
## 3  Female  Hispanic     7
## 4  Female     White    41
## 5  Female      <NA>     1
## 6    Male     Asian     2
## 7    Male Bi-Racial     1
## 8    Male     Black     5
## 9    Male  Hispanic    10
## 10   Male     White    27

Display Max, Min & Avg of BMIValues for Race > Gender

summarise(group_by(dfr, Race , Gender), max(BMIValue), min(BMIValue), mean(BMIValue))
## Source: local data frame [10 x 5]
## Groups: Race [?]
## 
##         Race Gender `max(BMIValue)` `min(BMIValue)` `mean(BMIValue)`
##        <chr>  <chr>           <dbl>           <dbl>            <dbl>
## 1      Asian Female        28.19431        24.42511         26.06524
## 2      Asian   Male        27.24885        22.66678         24.95782
## 3  Bi-Racial   Male        24.83473        24.83473         24.83473
## 4      Black Female        26.71407        24.64441         25.52777
## 5      Black   Male        26.60586        22.04640         24.43950
## 6   Hispanic Female        27.84206        23.06452         26.02787
## 7   Hispanic   Male        28.78164        23.62505         26.29876
## 8      White Female        28.24834        24.21459         26.39055
## 9      White   Male        31.70402        21.41385         27.67323
## 10      <NA> Female        27.90487        27.90487         27.90487

Display records for Dead People

filter(dfr, Died == "True")
##           ID        Name     Race Gender Smokes HeightInCms WeightInKgs
## 1  AC/AH/061      Lester    Black   Male  False      181.13       72.33
## 2  AC/AH/089        Dong    White   Male  False      179.24       75.54
## 3  AC/AH/150       Brett    White   Male   True      181.56       79.54
## 4  AC/SG/056     Merrill    Asian Female   True      166.19       67.46
## 5  AC/SG/179       Logan    White   Male  False      183.10       82.47
## 6  AC/AH/112         Pat    Black Female  False      160.57       63.54
## 7  AC/SG/182       Jamie Hispanic   Male   True      171.08       72.51
## 8  AC/AH/233      Marion    White Female  False      163.97       66.71
## 9  AC/SG/234        Luis Hispanic Female  False      164.88       68.07
## 10 AC/AH/180        Drew    White Female  False      160.80       64.77
## 11 AC/AH/154        Tony    White Female  False      160.03       64.30
## 12 AC/SG/003      Walter    White Female  False      161.83       66.03
## 13 AC/SG/010        Theo    Asian Female  False      159.32       64.92
## 14 AC/AH/133       Clyde Hispanic   Male  False      181.15       83.93
## 15 AC/AH/192   Dominique    White   Male  False      180.61       83.59
## 16 AC/AH/244        Sean    White Female  False      160.09       65.93
## 17 AC/SG/165       Elmer    White Female  False      162.18       67.81
## 18 AC/AH/221      Carlos    White Female  False      165.34       70.84
## 19 AC/SG/197       Stacy    White Female  False      159.44       66.21
## 20 AC/SG/134       Daryl    White Female   True      162.59       69.76
## 21 AC/AH/171       Devin    White Female  False      163.35       70.46
## 22 AC/SG/216        Alva    White Female  False      159.13       66.96
## 23 AC/SG/068   Valentine Hispanic Female  False      160.47       68.20
## 24 AC/AH/029      Lavern    White Female  False      164.47       71.78
## 25 AC/SG/116      Connie    Black   Male  False      184.34       90.41
## 26 AC/SG/084       Brian Hispanic   Male  False      174.25       80.93
## 27 AC/SG/016      Jimmie    Black Female  False      161.84       69.97
## 28 AC/AH/249       Jesus Hispanic Female   True      159.78       68.31
## 29 AC/SG/008        Dana    White   Male   True      169.66       77.30
## 30 AC/SG/065      Shayne    White Female  False      157.01       66.56
## 31 AC/AH/186 Christopher    White Female  False      157.95       67.41
## 32 AC/AH/176       Jerry    Asian   Male  False      175.21       83.65
## 33 AC/AH/219         Jay    White Female  False      163.47       72.89
## 34 AC/SG/101       Jason    White Female  False      159.23       69.96
## 35 AC/SG/123     Darnell    White Female   True      162.32       72.72
## 36 AC/SG/167       Jimmy    White Female  False      159.38       70.37
## 37 AC/SG/217        Dean    White Female  False      160.58       71.49
## 38 AC/AH/185      Ronald    White   Male  False      166.46       76.83
## 39 AC/SG/155     Raymond    White Female  False      158.35       69.72
## 40 AC/SG/046        Carl Hispanic   Male  False      171.41       81.70
## 41 AC/SG/191        Lacy Hispanic Female  False      159.33       70.68
## 42 AC/AH/156      George    White   Male  False      165.62       76.72
## 43 AC/AH/160        Rory    Asian Female  False      159.67       71.88
## 44 AC/AH/211         Son    White Female  False      157.16       69.64
## 45 AC/AH/049      Martin    White Female  False      160.06       72.37
## 46 AC/SG/181       Terry Hispanic   Male  False      177.14       88.70
## 47 AC/SG/055        Evan    White   Male  False      166.75       79.06
## 48 AC/SG/172     Whitney    White   Male  False      171.45       84.29
## 49 AC/SG/015       Shaun    White   Male   True      170.51       84.35
## 50 AC/AH/127        Jame    White   Male  False      167.75       82.06
## 51 AC/SG/067      Thomas    White   Male  False      167.51       84.15
## 52 AC/AH/248      Andrea    White   Male  False      178.64       97.05
## 53 AC/AH/104      Jeremy    White   Male   True      169.85       90.63
## 54 AC/SG/064         Jon    White   Male  False      169.16       90.08
##     BirthDate          State   Pet HealthGrade Died RecordDate BMIValue
## 1  16-11-1972      Wisconsin   Dog        <NA> True 25-12-2015 22.04640
## 2  11-03-1972     California  None      Normal True 25-12-2015 23.51295
## 3  03-05-1972       Kentucky   Dog  Good Heath True 25-02-2016 24.12933
## 4  27-11-1972        Indiana  None  Bad Health True 25-07-2016 24.42511
## 5  24-10-1972           Ohio   Dog  Bad Health True 25-09-2016 24.59910
## 6  26-06-1973     California  <NA>        <NA> True 25-01-2016 24.64441
## 7  25-03-1973      Louisiana  None  Bad Health True 25-09-2016 24.77419
## 8  23-12-1971           Ohio   Cat  Bad Health True 25-04-2016 24.81202
## 9  10-11-1971   Pennsylvania   Cat  Bad Health True 25-10-2016 25.03916
## 10 18-02-1973         Oregon   CAT  Good Heath True 25-03-2016 25.04966
## 11 30-08-1973     California   DOG  Good Heath True 25-02-2016 25.10777
## 12 11-07-1972         Oregon  None      Normal True 25-05-2016 25.21292
## 13 29-01-1973       New York   Cat      Normal True 25-06-2016 25.57631
## 14 13-10-1973     Washington   Cat  Bad Health True 25-02-2016 25.57647
## 15 24-03-1972       Michigan  None  Bad Health True 25-03-2016 25.62541
## 16 25-01-1973       Maryland  None        <NA> True 25-05-2016 25.72496
## 17 25-03-1972     Washington  Bird  Good Heath True 25-08-2016 25.78096
## 18 01-02-1972       Michigan   Dog        <NA> True 25-04-2016 25.91330
## 19 08-11-1972       New York   Cat  Good Heath True 25-10-2016 26.04528
## 20 28-05-1972          Texas   CAT      Normal True 25-08-2016 26.38875
## 21 16-04-1973     California  Bird  Bad Health True 25-03-2016 26.40611
## 22 19-06-1972        Alabama  None  Good Heath True 25-10-2016 26.44304
## 23 15-04-1972      Tennessee   Cat  Bad Health True 25-07-2016 26.48480
## 24 06-06-1973           Iowa  None      Normal True 25-11-2015 26.53567
## 25 05-06-1972        Florida  None  Bad Health True 25-08-2016 26.60586
## 26 06-03-1972       Virginia   DOG      Normal True 25-07-2016 26.65410
## 27 03-04-1972        Arizona   Cat  Bad Health True 25-06-2016 26.71407
## 28 23-04-1972        Alabama   Cat      Normal True 25-05-2016 26.75713
## 29 26-05-1973         Nevada   Dog  Good Heath True 25-05-2016 26.85472
## 30 05-04-1972     California   Dog  Bad Health True 25-07-2016 26.99968
## 31 06-05-1972     New Jersey   Dog  Bad Health True 25-03-2016 27.01998
## 32 01-05-1973       Virginia   Dog  Bad Health True 25-03-2016 27.24885
## 33 07-04-1972 North Carolina  Bird  Good Heath True 25-04-2016 27.27670
## 34 28-09-1973       Michigan   Dog      Normal True 25-07-2016 27.59307
## 35 03-09-1972 North Carolina  Bird  Good Heath True 25-08-2016 27.60005
## 36 30-09-1973     Washington  None      Normal True 25-09-2016 27.70256
## 37 11-11-1972           Ohio  None  Good Heath True 25-10-2016 27.72441
## 38 17-08-1972       Colorado  None        <NA> True 25-03-2016 27.72752
## 39 02-06-1972     California   Cat  Bad Health True 25-08-2016 27.80489
## 40 05-08-1973    Mississippi  Bird      Normal True 25-06-2016 27.80672
## 41 21-06-1973          Texas  None  Bad Health True 25-09-2016 27.84206
## 42 09-07-1972     California   Dog  Good Heath True 25-02-2016 27.96939
## 43 22-09-1973        Florida   Cat      Normal True 25-02-2016 28.19431
## 44 14-07-1973     California   Cat      Normal True 25-04-2016 28.19517
## 45 28-04-1972     California Horse      Normal True 25-12-2015 28.24834
## 46 24-11-1971        Indiana   CAT  Bad Health True 25-09-2016 28.26769
## 47 24-02-1972       Illinois  Bird  Bad Health True 25-07-2016 28.43316
## 48 25-02-1972        Florida   Dog      Normal True 25-09-2016 28.67484
## 49 09-11-1972     New Jersey   DOG  Bad Health True 25-06-2016 29.01252
## 50 29-10-1972          Texas   Dog  Good Heath True 25-01-2016 29.16127
## 51 19-07-1972   Pennsylvania  Bird      Normal True 25-07-2016 29.98974
## 52 12-01-1973        Indiana   Cat  Good Heath True 25-05-2016 30.41152
## 53 12-04-1972       Kentucky  None  Good Heath True 25-12-2015 31.41528
## 54 04-10-1972       Illinois   Cat      Normal True 25-07-2016 31.47988
##      BMILabel
## 1      Normal
## 2      Normal
## 3      Normal
## 4      Normal
## 5      Normal
## 6      Normal
## 7      Normal
## 8      Normal
## 9  Overweight
## 10 Overweight
## 11 Overweight
## 12 Overweight
## 13 Overweight
## 14 Overweight
## 15 Overweight
## 16 Overweight
## 17 Overweight
## 18 Overweight
## 19 Overweight
## 20 Overweight
## 21 Overweight
## 22 Overweight
## 23 Overweight
## 24 Overweight
## 25 Overweight
## 26 Overweight
## 27 Overweight
## 28 Overweight
## 29 Overweight
## 30 Overweight
## 31 Overweight
## 32 Overweight
## 33 Overweight
## 34 Overweight
## 35 Overweight
## 36 Overweight
## 37 Overweight
## 38 Overweight
## 39 Overweight
## 40 Overweight
## 41 Overweight
## 42 Overweight
## 43 Overweight
## 44 Overweight
## 45 Overweight
## 46 Overweight
## 47 Overweight
## 48 Overweight
## 49 Overweight
## 50 Overweight
## 51 Overweight
## 52      Obese
## 53      Obese
## 54      Obese

Display records for Hispanic Females

filter(dfr, Race == "Hispanic" & Gender == "Female")
##          ID      Name     Race Gender Smokes HeightInCms WeightInKgs
## 1 AC/AH/210     Keith Hispanic Female   True      170.03       66.68
## 2 AC/SG/234      Luis Hispanic Female  False      164.88       68.07
## 3 AC/AH/208  Lawrence Hispanic Female  False      165.80       71.77
## 4 AC/SG/068 Valentine Hispanic Female  False      160.47       68.20
## 5 AC/AH/249     Jesus Hispanic Female   True      159.78       68.31
## 6 AC/SG/122    Michal Hispanic Female  False      160.09       68.94
## 7 AC/SG/191      Lacy Hispanic Female  False      159.33       70.68
##    BirthDate          State  Pet HealthGrade  Died RecordDate BMIValue
## 1 28-08-1972       New York  Dog        <NA> False 25-03-2016 23.06452
## 2 10-11-1971   Pennsylvania  Cat  Bad Health  True 25-10-2016 25.03916
## 3 07-08-1973      Louisiana None  Good Heath False 25-03-2016 26.10802
## 4 15-04-1972      Tennessee  Cat  Bad Health  True 25-07-2016 26.48480
## 5 23-04-1972        Alabama  Cat      Normal  True 25-05-2016 26.75713
## 6 16-12-1971 South Carolina  DOG  Good Heath False 25-08-2016 26.89942
## 7 21-06-1973          Texas None  Bad Health  True 25-09-2016 27.84206
##     BMILabel
## 1     Normal
## 2 Overweight
## 3 Overweight
## 4 Overweight
## 5 Overweight
## 6 Overweight
## 7 Overweight

Display 7 sample records

set.seed(707)
sample_n(dfr, 7)
##           ID    Name     Race Gender Smokes HeightInCms WeightInKgs
## 10 AC/AH/114    Kris Hispanic   Male  False      177.75       74.84
## 44 AC/SG/204 Anthony    White Female  False      164.11       70.66
## 27 AC/AH/154    Tony    White Female  False      160.03       64.30
## 52 AC/SG/121    Rudy    White Female  False      163.94       71.47
## 73 AC/SG/046    Carl Hispanic   Male  False      171.41       81.70
## 67 AC/SG/123 Darnell    White Female   True      162.32       72.72
## 83 AC/AH/241 Lindsay    White Female  False      161.38       73.55
##     BirthDate          State  Pet HealthGrade  Died RecordDate BMIValue
## 10 19-11-1972   Pennsylvania Bird  Bad Health False 25-01-2016 23.68725
## 44 17-06-1972     California  Dog  Bad Health False 25-10-2016 26.23636
## 27 30-08-1973     California  DOG  Good Heath  True 25-02-2016 25.10777
## 52 12-03-1973       Michigan  Cat  Bad Health False 25-08-2016 26.59218
## 73 05-08-1973    Mississippi Bird      Normal  True 25-06-2016 27.80672
## 67 03-09-1972 North Carolina Bird  Good Heath  True 25-08-2016 27.60005
## 83 08-02-1972        Florida  Cat  Bad Health False 25-05-2016 28.24121
##      BMILabel
## 10     Normal
## 44 Overweight
## 27 Overweight
## 52 Overweight
## 73 Overweight
## 67 Overweight
## 83 Overweight

Summary

Note
The patient dataset consist of a lot of errors and missing data. These inconsistencies have been removed using various functions provided by the dplyr package so that the required data manipulation can be done. Once the data has been manipulated, the required outputs can be generated using different filters.

Objectives
The objectives set at the start have been met.