Importing data

library(dplyr)
## Warning: package 'dplyr' was built under R version 3.6.2
## 
## 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
library(readr)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.6.2
data<-read_csv("/Users/rebeccagibble/Downloads/SD4 NHIS Data.csv")
## Parsed with column specification:
## cols(
##   health = col_double(),
##   sex = col_double(),
##   bmi = col_double()
## )
head(data)
## # A tibble: 6 x 3
##   health   sex   bmi
##    <dbl> <dbl> <dbl>
## 1      3     1  33.4
## 2      1     2  20.2
## 3      3     1  27.3
## 4      3     2  38.6
## 5      1     2  40.0
## 6      2     2  18.8

Recoding health, sex, and BMI variables from their numeric format into their labeled format.

data1<-data%>%
  mutate(HealthStatus = ifelse(health==1, "Excellent",
                               ifelse(health==2,"Very Good",
                                      ifelse(health==3, "Good",
                                             ifelse(health==4, "Fair",
                                                    ifelse(health==5,"Poor",NA))))),
         MaleOrFemale= ifelse(sex==1, "Male",
                        ifelse(sex==2, "Female",NA)),
         BodyMassIndex=ifelse(bmi==0 | bmi>=9999,NA,bmi))%>%
select(HealthStatus,MaleOrFemale,BodyMassIndex)

head(data1)
## # A tibble: 6 x 3
##   HealthStatus MaleOrFemale BodyMassIndex
##   <chr>        <chr>                <dbl>
## 1 Good         Male                  33.4
## 2 Excellent    Female                20.2
## 3 Good         Male                  27.3
## 4 Good         Female                38.6
## 5 Excellent    Female                40.0
## 6 Very Good    Female                18.8

Percentage of Respondents in each Health Status Category

data2<-data1%>%
  select(HealthStatus)%>%
  na.exclude()
  
table(data2$HealthStatus)%>%
  prop.table()%>%
  round(2)
## 
## Excellent      Fair      Good      Poor Very Good 
##      0.25      0.11      0.27      0.03      0.34

Percentage of Repsondents per sex

data3<-data1%>%
  select(MaleOrFemale)%>%
  na.exclude()
  
table(data3$MaleOrFemale)%>%
  prop.table()%>%
  round(2)
## 
## Female   Male 
##   0.55   0.45

Mean BMI

data4<-data1%>%
  select(BodyMassIndex)%>%
  summarize(Avg_BodyMassIndex = mean(BodyMassIndex,na.rm=TRUE))
print(data4)
## # A tibble: 1 x 1
##   Avg_BodyMassIndex
##               <dbl>
## 1              28.0