#install.packages(readr)
#install.packages(dplyr)

library(readr)
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
Data <- read_csv("~/Tsukasa/NY/CUNY/Class/Spring 2019/Programming for Social Research/YRBS1991_2017(skillsdrill).csv")
## Parsed with column specification:
## cols(
##   survyear = col_double(),
##   sex = col_double(),
##   race4 = col_double(),
##   qntaughtHIV = col_double(),
##   qntaughtcondom = col_logical(),
##   sexpart = col_logical()
## )
head(Data)
## # A tibble: 6 x 6
##   survyear   sex race4 qntaughtHIV qntaughtcondom sexpart
##      <dbl> <dbl> <dbl>       <dbl> <lgl>          <lgl>  
## 1        1    NA     3           2 NA             NA     
## 2        1    NA    NA           1 NA             NA     
## 3        1    NA     1           1 NA             NA     
## 4        1    NA     1           2 NA             NA     
## 5        1    NA     4           2 NA             NA     
## 6        1     2     3           1 NA             NA
NewData <- Data%>%
  rename("race"=race4, "HIVEducation"=qntaughtHIV)%>%
  mutate(race=ifelse(race==1,"White",
         ifelse(race==2,"Black/African American",
         ifelse(race==3,"Hispanic/Latino",
         ifelse(race==4,"Other",NA)))),
         HIVEducation=ifelse(HIVEducation==1,"Yes",
         ifelse(HIVEducation==2,"No",NA)),
         sex=ifelse(sex==1,"female",
         ifelse(sex==2,"male",NA)))%>%
  select(race,HIVEducation,sex)

table(NewData$HIVEducation,NewData$race)%>%
  prop.table(2)%>%round(2)
##      
##       Black/African American Hispanic/Latino Other White
##   No                    0.14            0.18  0.15  0.12
##   Yes                   0.86            0.82  0.85  0.88