knitr::opts_chunk$set(echo = TRUE)

library(ggplot2)
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
library(tidyr)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v tibble  3.0.4     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.0
## v purrr   0.3.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(knitr)
setwd("C:/Users/BlaiseSevier/Desktop/R Work")

#reading in merged Advanced Placement  File -- with only the columns needed

fileAP <- "Advanced Placement-cali.csv"

ap.sch <- read.csv(fileAP)

### How to set your working directory 
## In quotation marks, ("C: /Users/BlaiseSevier/Desktop/R Work")

fileCA <- "CA.csv"
CA<- read.csv(fileCA)

CA.T <- sum(CA$Total)
CA.T
## [1] 1642370
### There are 1,642,370 High School students in CA????

CA.LEP <- sum(CA$LEP)
CA.LEP
## [1] 182799
CA.T - CA.LEP
## [1] 1459571
### There are 182,799 EL students in CA. 
summary(CA$LEP)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    0.00    6.00   35.00   87.21  121.00 1023.00
##################
CA.T - CA.LEP
## [1] 1459571
#######There are 1,459,571 non-EL students in CA.

non.el.ca <-1459571


###NEW Enrol Numbers
els.k12 <- 5296951
nonel.k12 <- 45625450


#Total Number of Students in HS
tot_enrol_hs <- 14183488
#Total Number of Non-Els in HS
non.el.hs <- 13108063
#Total Number of LEP in HS 
tot_lep_hs <- 1075425 

CRDC Survey Information

For more information about the school form see: https://www2.ed.gov/about/offices/list/ocr/docs/2017-18-crdc-school-form.pdf.

TOT_APENR_M Students Enrolled in at least one AP Course: Calculated Male Total TOT_APENR_F Students Enrolled in at least one AP Course: Calculated Female Total SCH_APENR_LEP_M Students Enrolled in at least one AP Course: LEP Male SCH_APENR_LEP_F Students Enrolled in at least one AP Course: LEP Female

TOT_APMATHENR_M Student Enrollment in AP Mathematics: Calculated Male Total TOT_APMATHENR_F Student Enrollment in AP Mathematics: Calculated Female Total SCH_APMATHENR_LEP_M Student Enrollment in AP Mathematics: LEP Male SCH_APMATHENR_LEP_F Student Enrollment in AP Mathematics: LEP Female

TOT_APSCIENR_M Student Enrollment in AP Science: Calculated Male Total TOT_APSCIENR_F Student Enrollment in AP Science: Calculated Female Total SCH_APSCIENR_LEP_M Student Enrollment in AP Science: LEP Male SCH_APSCIENR_LEP_F Student Enrollment in AP Science: LEP Female

TOT_APOTHENR_M Students Enrollment in Other AP Subjects: Calculated Male Total TOT_APOTHENR_F Students Enrollment in Other AP Subjects: Calculated Female Total SCH_APOTHENR_LEP_M Students Enrollment in Other AP Subjects: LEP Male SCH_APOTHENR_LEP_F Students Enrollment in Other AP Subjects: LEP Female

Change Code from 0s to 9s

#Code to change the -9s to 0s

ap.sch[ap.sch==-8]<-0
ap.sch[ap.sch==-9]<-0
ap.sch[ap.sch==-8]<-0
ap.sch[ap.sch==-6]<-0
ap.sch[ap.sch==-5]<-0
ap.sch[ap.sch==-3]<-0

## important columns 27:30


# Reserve code value
# Definition
# -3 | Skip Logic Failure
# -5 | Action Plan
# -6 | Force Certified
# -8 | EDFacts Missing Data
# -9 | Not Applicable / Skipped
# -11 | Suppressed Data

TOT_APENR_M Students Enrolled in at least one AP Course: Calculated Male Total TOT_APENR_F Students Enrolled in at least one AP Course: Calculated Female Total SCH_APENR_LEP_M Students Enrolled in at least one AP Course: LEP Male SCH_APENR_LEP_F Students Enrolled in at least one AP Course: LEP Female

Non-English Learner Male Students Enrolled in AP Courses

#Computes the total number of a non-English Learner male students in ap courses

#dat$NonELM<- (dat$TOT_ENR_M - dat$TOT_LEPENR_M)

ap.sch$NonELM <- (ap.sch$TOT_APENR_M - ap.sch$SCH_APENR_LEP_M)

sum(ap.sch$NonELM)
## [1] 190331
#There are 1,292,997 Non-English Learner Male Students Enrolled in AP Courses 

#There are 190,331 Non-English Learner Male Students Enrolled in AP Courses in California

Non-English Learner Female Students in Advanced Placement

#Total female non-EL 
#dat$NonELF <-dat$TOT_ENR_F-dat$TOT_LEPENR_F

ap.sch$NonELF <- (ap.sch$TOT_APENR_F - ap.sch$SCH_APENR_LEP_F)

sum(ap.sch$NonELF)
## [1] 252107
#There are 1,672,743 Non-English Learner Females Enrolled in AP courses.
#There are 252,107 Non-English Learner Females Enrolled in AP courses in California

Total Non ELs in Advanced Placement

#total non EL
#dat$NonEL<-dat$NonELF + dat$NonELM

ap.sch$NonEL <- ap.sch$NonELF + ap.sch$NonELM

non.el.ap <- sum(ap.sch$NonEL)

non.el.ap
## [1] 442438
#There are 2,965,740 Non-English Learners Enrolled in AP Courses 

#There are 442,438 Non-English Learners Enrolled in AP Courses in California

English Learners in Advanced Placement

English Learner Males in Advanced Placement

#Total Lep Male in Advanced Placement 

#dat$ELMGT <- dat$SCH_GTENR_LEP_M

ap.sch$ELM.ap <- ap.sch$SCH_APENR_LEP_M

sum(ap.sch$ELM.ap)
## [1] 5622
## There is 29,677 English Learner Males in AP Courses in US

## There is 5,622 English Learner Males in AP Courses in California

English Learner Females in Advanced Placement

#Total LEP Female in GT
#dat$ELFGT <- dat$SCH_GTENR_LEP_F

ap.sch$ELF.ap <- ap.sch$SCH_APENR_LEP_F

sum(ap.sch$ELF.ap)
## [1] 6689
## There are 35,488 EL Females in AP Classes 

## There are  6,689 EL Females in AP Classes in California

Total English Learners in Advanced Placement

#dat$ELEnrol <- dat$TOT_LEPENR_M + dat$TOT_LEPENR_F

ap.sch$ELEnrolap <- ap.sch$ELM.ap + ap.sch$ELF.ap

els.ap <- sum(ap.sch$ELEnrolap)

sum(els.ap)
## [1] 12311
## There is 65,165 English learners in AP Courses 

## There are 12,311 ELs in AP Courses in California 

Percentage of ELs and Non ELs in AP Courses

#Percentage of ELs in AP courses in HS 6% in the United States

#Percentage of Els in Ap in California out of Els high school in California is 6.73%

round(els.ap/CA.LEP*100,2)
## [1] 6.73
#Percentage of non-ELs in AP courses in HS 23% in the United States


#Percentage of non-Els in AP courses in HS in California is 30.31

round(non.el.ap/non.el.ca *100,2)
## [1] 30.31

Exams

Percentage of English Learners Taking One or More Exam

#Total Number of ELs who too One or More Exam

one.or.more.el <- sum(ap.sch$SCH_APEXAM_ONEORMORE_LEP_F) + sum(ap.sch$SCH_APEXAM_ONEORMORE_LEP_M)

# 7,438 ELs took one or more AP Exam 

 sum(ap.sch$SCH_APEXAM_ONEORMORE_LEP_F)/one.or.more.el
## [1] 0.5750202
 sum(ap.sch$SCH_APEXAM_ONEORMORE_LEP_M)/one.or.more.el
## [1] 0.4249798
(one.or.more.el/els.ap*100)
## [1] 60.41751
## ELs 60.7% took one or more ap exam in the US
 
 ## Els in California 60.4% took one ormore ap exam in California

Percentage of Non-ELs Taking the Exam

## Number of Non-ELs taking the Exam

((sum(ap.sch$TOT_APEXAM_ONEORMORE_F) - sum(ap.sch$SCH_APEXAM_ONEORMORE_LEP_F)))/non.el.ap*100 ##42.92% Non El Females 
## [1] 42.92195
(sum(ap.sch$TOT_APEXAM_ONEORMORE_M) - sum(ap.sch$SCH_APEXAM_ONEORMORE_LEP_M))/non.el.ap*100 ## 31.5% Non El Males
## [1] 31.54815
non.els.APEXAM.oneormore <-(sum(ap.sch$TOT_APEXAM_ONEORMORE_F) - sum(ap.sch$SCH_APEXAM_ONEORMORE_LEP_F)) + (sum(ap.sch$TOT_APEXAM_ONEORMORE_M) - sum(ap.sch$SCH_APEXAM_ONEORMORE_LEP_M))

#329,484 non els took AP Exam 

non.els.APEXAM.oneormore
## [1] 329484
#There are 2,965,740 Non-English Learners Enrolled in AP Courses 

non.els.APEXAM.oneormore/non.el.ap*100
## [1] 74.4701
##74.47% OF NON Els took one or more AP Exam. 

Percentage of ELs Not Taking an Exam

NONExam <- sum(ap.sch$SCH_APEXAM_NONE_LEP_F) + sum(ap.sch$SCH_APEXAM_NONE_LEP_M)

(NONExam/els.ap*100)
## [1] 37.17813
####

(one.or.more.el/els.ap*100) + (NONExam/els.ap*100)
## [1] 97.59565