dt<-read.csv(file.choose(),sep=",") View(dt) summary(dt) dt2<-read.csv(file.choose(),sep=",") View(dt2)
dt<-read.csv("D:/DOWNLOADS/CASchools.csv",sep=",")
dt2<-read.csv("D:/DOWNLOADS/heart.csv",sep=",")
kita bisa melakukan teknik resampling Jackknife dengan menggunakan code berikut :
n<-nrow(dt)
x.bar<-mean(dt$income)
Se.x<-sd(dt$income)/sqrt(n)
jack.x.bar<-numeric(n)
for (i in 1:n){
temp<-dt$income[-c(i)]
jack.x.bar[i]<-mean(temp)
}
jack.mean.x.bar<-mean(jack.x.bar)
jack.SE<-sqrt(((n-1)/n)*sum((jack.x.bar-jack.mean.x.bar)^2))
#Tingkat Kepercayaan 95% untuk rata-rata
t.star<-qt(p=0.975,df=n-1)
x.bar+c(-1,1)*t.star*Se.x
FALSE [1] 14.62353 16.00965
res<-jack.mean.x.bar+c(-1,1)*t.star*jack.SE
hasil Confident Interval untuk rata rata dengan Jackknife adalah 14.6235277, 16.0096484
###Bootstrap kita bisa melakukan teknik resampling bootstrap dengan menggunakan code berikut :
library(mosaic)
x<-dt$income
theta.hat<-mean(x)
B<-1000
boot.mean<-do(B)*mean(resample(x,replace=TRUE))
boot.mean<-data.frame(boot.mean)
alpha<-0.05
quantile(x=boot.mean$mean,probs=c(alpha/2,1-alpha/2),data=boot.mean,na.rm=TRUE)
FALSE 2.5% 97.5%
FALSE 14.66248 16.02973
SE.boot<-sd(boot.mean$mean)
res2<-theta.hat+c(-1,1)*qnorm(p=1-alpha/2)*SE.boot
Hasil Confident Interval untuk rata rata AHH pria 2015 dengan bootstrap adalah 14.6235277, 16.0096484
# Mean
mean(dt$income)
## [1] 15.31659
# Median
median(dt$income)
## [1] 13.7278
# Fraktil
quantile(dt$expenditure,c(0.25,0.5,0.75))
## 25% 50% 75%
## 4906.180 5214.517 5601.401
# Range
range(dt$expenditure)
## [1] 3926.070 7711.507
max(dt$expenditure)-min(dt$expenditure)
## [1] 3785.437
# Interquartile range
quantile(dt$expenditure,0.75)-quantile(dt$expenditure,0.25)
## 75%
## 695.2213
# Varians
var(dt$income)
## [1] 52.21348
# Standar deviasi (Simpangan baku)
sd(dt$income)
## [1] 7.22589
# Rangkuman statistik deskriptif
summary(dt$income)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 5.335 10.639 13.728 15.317 17.629 55.328
summary(dt)
## X district school county
## Min. : 1.0 Min. :61382 Length:420 Length:420
## 1st Qu.:105.8 1st Qu.:64308 Class :character Class :character
## Median :210.5 Median :67761 Mode :character Mode :character
## Mean :210.5 Mean :67473
## 3rd Qu.:315.2 3rd Qu.:70419
## Max. :420.0 Max. :75440
## grades students teachers calworks
## Length:420 Min. : 81.0 Min. : 4.85 Min. : 0.000
## Class :character 1st Qu.: 379.0 1st Qu.: 19.66 1st Qu.: 4.395
## Mode :character Median : 950.5 Median : 48.56 Median :10.520
## Mean : 2628.8 Mean : 129.07 Mean :13.246
## 3rd Qu.: 3008.0 3rd Qu.: 146.35 3rd Qu.:18.981
## Max. :27176.0 Max. :1429.00 Max. :78.994
## lunch computer expenditure income
## Min. : 0.00 Min. : 0.0 Min. :3926 Min. : 5.335
## 1st Qu.: 23.28 1st Qu.: 46.0 1st Qu.:4906 1st Qu.:10.639
## Median : 41.75 Median : 117.5 Median :5215 Median :13.728
## Mean : 44.71 Mean : 303.4 Mean :5312 Mean :15.317
## 3rd Qu.: 66.86 3rd Qu.: 375.2 3rd Qu.:5601 3rd Qu.:17.629
## Max. :100.00 Max. :3324.0 Max. :7712 Max. :55.328
## english read math
## Min. : 0.000 Min. :604.5 Min. :605.4
## 1st Qu.: 1.941 1st Qu.:640.4 1st Qu.:639.4
## Median : 8.778 Median :655.8 Median :652.5
## Mean :15.768 Mean :655.0 Mean :653.3
## 3rd Qu.:22.970 3rd Qu.:668.7 3rd Qu.:665.9
## Max. :85.540 Max. :704.0 Max. :709.5
summary(dt2)
## Age Sex ChestPainType RestingBP
## Min. :28.00 Length:918 Length:918 Min. : 0.0
## 1st Qu.:47.00 Class :character Class :character 1st Qu.:120.0
## Median :54.00 Mode :character Mode :character Median :130.0
## Mean :53.51 Mean :132.4
## 3rd Qu.:60.00 3rd Qu.:140.0
## Max. :77.00 Max. :200.0
## Cholesterol FastingBS RestingECG MaxHR
## Min. : 0.0 Min. :0.0000 Length:918 Min. : 60.0
## 1st Qu.:173.2 1st Qu.:0.0000 Class :character 1st Qu.:120.0
## Median :223.0 Median :0.0000 Mode :character Median :138.0
## Mean :198.8 Mean :0.2331 Mean :136.8
## 3rd Qu.:267.0 3rd Qu.:0.0000 3rd Qu.:156.0
## Max. :603.0 Max. :1.0000 Max. :202.0
## ExerciseAngina Oldpeak ST_Slope HeartDisease
## Length:918 Min. :-2.6000 Length:918 Min. :0.0000
## Class :character 1st Qu.: 0.0000 Class :character 1st Qu.:0.0000
## Mode :character Median : 0.6000 Mode :character Median :1.0000
## Mean : 0.8874 Mean :0.5534
## 3rd Qu.: 1.5000 3rd Qu.:1.0000
## Max. : 6.2000 Max. :1.0000
# Pengaturan variabel
library(dplyr)
dt2.male<-dt2%>%filter(Sex=="M")
total.dt2.male<-nrow(dt2.male)
total.dt2.male
## [1] 725
total.dt2<-nrow(dt2)
total.dt2
## [1] 918
# Two-tailed
test.prop.dt2.sex<-prop.test(x=total.dt2.male, n=total.dt2, p=0.5, correct = FALSE)
test.prop.dt2.sex
##
## 1-sample proportions test without continuity correction
##
## data: total.dt2.male out of total.dt2
## X-squared = 308.31, df = 1, p-value < 2.2e-16
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.7622210 0.8148848
## sample estimates:
## p
## 0.7897603
# One tailed
# Less
test.less<-prop.test(x=total.dt2.male, n=total.dt2, p=0.5,alternative="less", correct = FALSE)
test.less
##
## 1-sample proportions test without continuity correction
##
## data: total.dt2.male out of total.dt2
## X-squared = 308.31, df = 1, p-value = 1
## alternative hypothesis: true p is less than 0.5
## 95 percent confidence interval:
## 0.0000000 0.8110141
## sample estimates:
## p
## 0.7897603
# Greater
test.greater<-prop.test(x=total.dt2.male, n=total.dt2, p=0.5,alternative="greater", correct = FALSE)
test.greater
##
## 1-sample proportions test without continuity correction
##
## data: total.dt2.male out of total.dt2
## X-squared = 308.31, df = 1, p-value < 2.2e-16
## alternative hypothesis: true p is greater than 0.5
## 95 percent confidence interval:
## 0.7668037 1.0000000
## sample estimates:
## p
## 0.7897603
# Regresi Linear Sederhana
x<-dt$expenditure
y<-dt$income
plot(x,y)
abline(lm(y~x))
lm(y~x)
##
## Call:
## lm(formula = y ~ x)
##
## Coefficients:
## (Intercept) x
## -3.726430 0.003585
fit <-lm(y~x)
summary(fit)
##
## Call:
## lm(formula = y ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -14.479 -4.272 -1.167 2.494 35.895
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -3.7264305 2.8313784 -1.316 0.189
## x 0.0035846 0.0005292 6.773 4.29e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.867 on 418 degrees of freedom
## Multiple R-squared: 0.0989, Adjusted R-squared: 0.09674
## F-statistic: 45.88 on 1 and 418 DF, p-value: 4.286e-11
# Regresi Linear Berganda
lm(income~math+read,english, data=dt)
##
## Call:
## lm(formula = income ~ math + read, data = dt, subset = english)
##
## Coefficients:
## (Intercept) math read
## -70.47963 -0.02069 0.14886
fit1<-lm(income~math+read,english, data=dt)
summary(fit1)
##
## Call:
## lm(formula = income ~ math + read, data = dt, subset = english)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.325 -2.001 -0.330 1.712 12.627
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -70.47963 5.07159 -13.897 < 2e-16 ***
## math -0.02069 0.02955 -0.700 0.484
## read 0.14886 0.02718 5.477 8.53e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.038 on 334 degrees of freedom
## Multiple R-squared: 0.4932, Adjusted R-squared: 0.4902
## F-statistic: 162.5 on 2 and 334 DF, p-value: < 2.2e-16
library(survival, pos=22)
library(TH.data, pos=22)
## Warning: package 'TH.data' was built under R version 4.0.5
## Loading required package: MASS
## Warning: package 'MASS' was built under R version 4.0.5
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
##
## Attaching package: 'TH.data'
## The following object is masked _by_ 'package:MASS':
##
## geyser
library(multcomp, pos=22)
## Warning: package 'multcomp' was built under R version 4.0.5
## Loading required package: mvtnorm
## Warning: package 'mvtnorm' was built under R version 4.0.5
library(abind, pos=25)
library(car)
## Warning: package 'car' was built under R version 4.0.5
## Loading required package: carData
##
## Attaching package: 'car'
## The following objects are masked from 'package:mosaic':
##
## deltaMethod, logit
## The following object is masked from 'package:dplyr':
##
## recode
AnovaModel.3 <- aov(income~county, data=dt)
summary(AnovaModel.3)
## Df Sum Sq Mean Sq F value Pr(>F)
## county 44 11840 269.08 10.05 <2e-16 ***
## Residuals 375 10038 26.77
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
AnovaModel.4 <- aov(expenditure ~county, data=dt)
summary(AnovaModel.4)
## Df Sum Sq Mean Sq F value Pr(>F)
## county 44 52122246 1184597 3.821 6.39e-13 ***
## Residuals 375 116263876 310037
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
AnovaModel.11 <- lm(income ~ county, data=dt, contrasts=list(county ="contr.Sum"))
Anova(AnovaModel.11)
## Anova Table (Type II tests)
##
## Response: income
## Sum Sq Df F value Pr(>F)
## county 11840 44 10.053 < 2.2e-16 ***
## Residuals 10038 375
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Tapply(income ~ county, mean, na.action=na.omit, data=dt) # means
## Alameda Butte Calaveras Contra Costa El Dorado
## 22.690001 9.205243 13.243000 25.265674 15.964900
## Fresno Glenn Humboldt Imperial Inyo
## 9.269000 10.639000 12.879294 9.677167 13.522333
## Kern Kings Lake Lassen Los Angeles
## 11.217030 10.820074 10.796500 12.819000 14.644124
## Madera Marin Mendocino Merced Monterey
## 12.642517 32.185312 10.035000 10.018221 13.134043
## Nevada Orange Placer Riverside Sacramento
## 15.325334 17.433482 16.777414 12.861125 11.987568
## San Benito San Bernardino San Diego San Joaquin San Luis Obispo
## 13.630000 13.394711 17.448104 13.397000 16.864500
## San Mateo Santa Barbara Santa Clara Santa Cruz Shasta
## 27.461052 22.780021 24.026920 20.398662 12.142857
## Siskiyou Sonoma Stanislaus Sutter Tehama
## 11.202815 17.445289 13.498087 11.984000 10.507125
## Trinity Tulare Tuolumne Ventura Yuba
## 13.103500 9.918167 12.016389 15.319697 11.227000
Tapply(income ~ county, sd, na.action=na.omit, data=dt) # std. deviations
## Alameda Butte Calaveras Contra Costa El Dorado
## NA 1.3535137 NA 10.3077626 2.2472260
## Fresno Glenn Humboldt Imperial Inyo
## 2.2957477 0.0000000 1.6487372 0.8997434 NA
## Kern Kings Lake Lassen Los Angeles
## 3.8232827 0.6767858 1.0698529 0.3634376 5.4256976
## Madera Marin Mendocino Merced Monterey
## 2.0131309 11.4800799 NA 1.8263700 3.6342600
## Nevada Orange Placer Riverside Sacramento
## 2.4029508 3.6630183 2.6644683 2.2943909 1.9418465
## San Benito San Bernardino San Diego San Joaquin San Luis Obispo
## 0.0000000 3.1729992 6.8641375 3.3610909 8.3346674
## San Mateo Santa Barbara Santa Clara Santa Cruz Shasta
## 10.9824315 11.3406484 8.9794769 4.8016953 1.4590718
## Siskiyou Sonoma Stanislaus Sutter Tehama
## 1.4316131 2.6648830 1.3812515 2.1644668 0.8384520
## Trinity Tulare Tuolumne Ventura Yuba
## 0.2397090 2.3670582 2.4042008 5.7172809 1.8031224
xtabs(~ county, data=dt) # counts
## county
## Alameda Butte Calaveras Contra Costa El Dorado
## 1 6 1 7 10
## Fresno Glenn Humboldt Imperial Inyo
## 12 3 17 6 1
## Kern Kings Lake Lassen Los Angeles
## 27 9 2 5 27
## Madera Marin Mendocino Merced Monterey
## 5 8 1 11 7
## Nevada Orange Placer Riverside Sacramento
## 9 11 11 4 7
## San Benito San Bernardino San Diego San Joaquin San Luis Obispo
## 3 10 21 6 2
## San Mateo Santa Barbara Santa Clara Santa Cruz Shasta
## 17 11 20 7 13
## Siskiyou Sonoma Stanislaus Sutter Tehama
## 9 29 7 6 8
## Trinity Tulare Tuolumne Ventura Yuba
## 2 24 6 9 2
AnovaModel.11 <- lm(expenditure ~ county, data=dt, contrasts=list(county ="contr.Sum"))
Anova(AnovaModel.11)
## Anova Table (Type II tests)
##
## Response: expenditure
## Sum Sq Df F value Pr(>F)
## county 52122246 44 3.8208 6.391e-13 ***
## Residuals 116263876 375
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Tapply(expenditure ~ county, mean, na.action=na.omit, data=dt) # means
## Alameda Butte Calaveras Contra Costa El Dorado
## 6384.911 5776.724 5482.677 5269.445 5309.967
## Fresno Glenn Humboldt Imperial Inyo
## 5396.978 4363.346 5449.528 5036.141 5189.628
## Kern Kings Lake Lassen Los Angeles
## 5165.863 5267.910 5762.261 4944.442 5055.672
## Madera Marin Mendocino Merced Monterey
## 5587.214 6158.656 6089.911 5227.237 5171.937
## Nevada Orange Placer Riverside Sacramento
## 5560.375 4980.176 5026.351 4904.150 5212.460
## San Benito San Bernardino San Diego San Joaquin San Luis Obispo
## 5137.167 5015.355 5412.878 4885.268 5058.711
## San Mateo Santa Barbara Santa Clara Santa Cruz Shasta
## 5715.444 5307.868 5560.497 5889.167 5479.120
## Siskiyou Sonoma Stanislaus Sutter Tehama
## 6241.181 5660.046 4855.546 4613.043 5008.996
## Trinity Tulare Tuolumne Ventura Yuba
## 5827.908 4852.233 5408.842 4964.327 5384.865
Tapply(expenditure ~ county, sd, na.action=na.omit, data=dt) # std. deviations
## Alameda Butte Calaveras Contra Costa El Dorado
## NA 757.88607 NA 380.54706 281.70541
## Fresno Glenn Humboldt Imperial Inyo
## 554.38457 301.89106 523.28313 566.73002 NA
## Kern Kings Lake Lassen Los Angeles
## 511.38782 725.92476 151.50177 213.83224 348.02586
## Madera Marin Mendocino Merced Monterey
## 725.43480 475.45764 NA 438.82091 544.57305
## Nevada Orange Placer Riverside Sacramento
## 723.33354 199.55427 277.30837 142.70637 369.77360
## San Benito San Bernardino San Diego San Joaquin San Luis Obispo
## 248.69548 496.87814 384.88565 207.01949 277.07365
## San Mateo Santa Barbara Santa Clara Santa Cruz Shasta
## 1086.00600 845.27314 428.69782 823.20936 762.24326
## Siskiyou Sonoma Stanislaus Sutter Tehama
## 443.43863 677.67998 223.20636 410.03572 331.31024
## Trinity Tulare Tuolumne Ventura Yuba
## 79.93725 625.97029 269.23665 454.81323 860.58866
xtabs(~ county, data=dt) # counts
## county
## Alameda Butte Calaveras Contra Costa El Dorado
## 1 6 1 7 10
## Fresno Glenn Humboldt Imperial Inyo
## 12 3 17 6 1
## Kern Kings Lake Lassen Los Angeles
## 27 9 2 5 27
## Madera Marin Mendocino Merced Monterey
## 5 8 1 11 7
## Nevada Orange Placer Riverside Sacramento
## 9 11 11 4 7
## San Benito San Bernardino San Diego San Joaquin San Luis Obispo
## 3 10 21 6 2
## San Mateo Santa Barbara Santa Clara Santa Cruz Shasta
## 17 11 20 7 13
## Siskiyou Sonoma Stanislaus Sutter Tehama
## 9 29 7 6 8
## Trinity Tulare Tuolumne Ventura Yuba
## 2 24 6 9 2
with(dt,hist(income, scale="frequency", breaks="Sturges", col="darkgray"))
## Warning in plot.window(xlim, ylim, "", ...): "scale" is not a graphical
## parameter
## Warning in title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...): "scale"
## is not a graphical parameter
## Warning in axis(1, ...): "scale" is not a graphical parameter
## Warning in axis(2, ...): "scale" is not a graphical parameter
densityPlot( ~ income, data=dt, bw=bw.SJ, adjust=1, kernel=dnorm, method="adaptive")
library(aplpack, pos=26)
## Warning: package 'aplpack' was built under R version 4.0.5
with(dt, stem.leaf(income, na.rm=TRUE))
## 1 | 2: represents 1.2
## leaf unit: 0.1
## n: 420
## 2 5 | 36
## 6 6 | 2569
## 24 7 | 013333333344455799
## 47 8 | 01111222234557888999999
## 73 9 | 00444566666666777788999999
## 112 10 | 000000000222222333344455555566666666699
## 155 11 | 0011111111222222344444455556667788888889999
## 184 12 | 00112333444555555666667788999
## (31) 13 | 1222233334444455555666777777799
## 205 14 | 0000000001111111122222224445555556666789
## 165 15 | 000111111122233344444555555677779
## 132 16 | 0222233333446667999
## 113 17 | 1334555667777789
## 97 18 | 012233333555666667778
## 76 19 | 001135789
## 67 20 | 0144457789
## 57 21 | 0156999
## 50 22 | 00145567888
## 39 23 | 46778
## 34 24 | 6
## 33 25 | 0002467
## 26 |
## 26 27 | 489
## 23 28 | 7
## HI: 30.6284999847412 30.8400001525879 31.0520000457764 33.4550018310547 34.1595001220703 34.3009986877441 35.3419990539551 35.4809989929199 35.810001373291 35.810001373291 36.173999786377 36.173999786377 38.6285705566406 40.2639999389648 40.4020004272461 41.0929985046387 41.7341079711914 43.2299995422363 43.2299995422363 49.9389991760254 50.6769981384277 55.3279991149902
Boxplot( ~ income, data=dt, id=list(method="y"))
## [1] "405" "414" "404" "402" "413" "417" "387" "415" "411" "408"
scatterplot(income~expenditure, regLine=FALSE, smooth=FALSE, boxplots=FALSE, data=dt)
library(colorspace, pos=27)
## Warning: package 'colorspace' was built under R version 4.0.5
boxplot(dt$math)
shapiro.test(dt$math)
Shapiro-Wilk normality test
data: dt$math
W = 0.99366, p-value = 0.07594
res <- t.test(dt$math,mu=650)
res
One Sample t-test
data: dt$math
t = 3.6527, df = 419, p-value = 0.0002924
alternative hypothesis: true mean is not equal to 650
95 percent confidence interval:
651.5438 655.1414
sample estimates:
mean of x
653.3426
boxplot(dt$math)
boxplot(dt$read)
shapiro.test(dt$math)
Shapiro-Wilk normality test
data: dt$math
W = 0.99366, p-value = 0.07594
shapiro.test(dt$read)
Shapiro-Wilk normality test
data: dt$read
W = 0.99472, p-value = 0.1597
res.ftest <- var.test(math~grades, data =dt)
res.ftest
F test to compare two variances
data: math by grades
F = 1.1157, num df = 60, denom df = 358, p-value = 0.5432
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.7765411 1.6926969
sample estimates:
ratio of variances
1.115655
res <- t.test(read~grades, data =dt, var.equal = TRUE)
res
Two Sample t-test
data: read by grades
t = 3.0136, df = 418, p-value = 0.002739
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
2.890422 13.733932
sample estimates:
mean in group KK-06 mean in group KK-08
662.0754 653.7632
library(foreign) AHH.dependen <- read.spss("D:/kerjaanku@_@/Praktikum Komstat/dua sampel dependen.sav",to.data.frame = TRUE)
View(dt2) ## Menghitung Beda Sampel
d <- with(AHH.dependen, AHHwanita[Tahun == "2018"] - AHHwanita[Tahun == "2019"])
res <- shapiro.test(d) res
res <- t.test(AHHwanita ~ Tahun, data = AHH.dependen, paired = TRUE) res
score.math<- data.frame(dt$math)
z_score <- function(x) {
(x - mean(x)) / sd(x)
}
apply(score.math,2,z_score)
dt.math
[1,] 1.954622283
[2,] 0.456292718
[3,] -0.130242496
[4,] -0.524822034
[5,] -0.716777711
[6,] -2.556365430
[7,] -2.364409753
[8,] -2.177784912
[9,] -1.985829234
[10,] -2.129794365
[11,] -1.847191685
[12,] -1.991160071
[13,] -1.788539466
[14,] -1.639240244
[15,] -1.724553155
[16,] -1.783205375
[17,] -1.543259150
[18,] -1.687227536
[19,] -1.751213846
[20,] -1.815200157
[21,] -1.489937767
[22,] -1.623241225
[23,] -1.745883010
[24,] -1.596580533
[25,] -1.473942003
[26,] -1.713888227
[27,] -1.457946239
[28,] -1.223330851
[29,] -1.399294019
[30,] -1.756544683
[31,] -1.313977854
[32,] -1.409955692
[33,] -1.255325634
[34,] -1.479276094
[35,] -1.415289783
[36,] -1.340638545
[37,] -1.233995779
[38,] -1.495271858
[39,] -1.239329870
[40,] -1.399294019
[41,] -1.313977854
[42,] -0.967388863
[43,] -1.367299237
[44,] -0.914067480
[45,] -1.191339323
[46,] -1.276652234
[47,] -1.180674396
[48,] -1.303312926
[49,] -1.271321398
[50,] -1.106026412
[51,] -1.047370938
[52,] -1.399294019
[53,] -1.207335087
[54,] -1.020710246
[55,] -1.260656470
[56,] -1.218000015
[57,] -1.084696557
[58,] -1.404624856
[59,] -1.372633328
[60,] -1.111357248
[61,] -0.887406788
[62,] -0.935397335
[63,] -0.887406788
[64,] -1.090027393
[65,] -1.079365720
[66,] -1.265990561
[67,] -0.914067480
[68,] -1.218000015
[69,] -0.887406788
[70,] -1.164678632
[71,] -0.892740879
[72,] -1.186008487
[73,] -1.052705029
[74,] -0.914067480
[75,] -0.780764022
[76,] -1.132687104
[77,] -1.058035865
[78,] -1.452615403
[79,] -1.244660706
[80,] -0.892740879
[81,] -0.807424714
[82,] -0.988718718
[83,] -0.780764022
[84,] -0.802093877
[85,] -0.802093877
[86,] -1.361968400
[87,] -0.652794655
[88,] -0.636795637
[89,] -0.834085405
[90,] -0.823420478
[91,] -0.914067480
[92,] -1.042040101
[93,] -1.223330851
[94,] -1.255325634
[95,] -0.567478489
[96,] -0.748772494
[97,] -0.924732407
[98,] -0.690117020
[99,] -0.380853648
[100,] -0.812758805
[101,] -0.732776730
[102,] -0.684786183
[103,] -0.807424714
[104,] -0.930063244
[105,] -0.775433185
[106,] -0.839419496
[107,] -0.828754569
[108,] -0.812758805
[109,] -0.802093877
[110,] -0.418179267
[111,] -0.887406788
[112,] -0.716777711
[113,] -0.535486961
[114,] -0.551482725
[115,] -0.876741861
[116,] -0.615469036
[117,] -0.519491197
[118,] -0.482165578
[119,] -0.588808344
[120,] -0.460835723
[121,] -0.572812580
[122,] -0.316867338
[123,] -0.466169814
[124,] -1.090027393
[125,] -0.492830506
[126,] -0.508826270
[127,] -0.332866356
[128,] -0.290206646
[129,] -0.439509122
[130,] -0.562147653
[131,] -1.015379410
[132,] 0.024387562
[133,] -0.620799872
[134,] -0.919401571
[135,] -0.503492179
[136,] -0.887406788
[137,] -0.743438403
[138,] -0.407514340
[139,] -0.460835723
[140,] -0.546151889
[141,] -0.492830506
[142,] -0.700781947
[143,] -0.322201429
[144,] -1.047370938
[145,] -1.079365720
[146,] -0.530152870
[147,] -0.370188721
[148,] -0.327532265
[149,] -0.391518576
[150,] -0.738107566
[151,] -0.631464800
[152,] -0.194228807
[153,] -0.114246732
[154,] -0.434175031
[155,] -0.498161342
[156,] -0.210224571
[157,] -0.274210882
[158,] -0.386187739
[159,] -0.092920132
[160,] -0.204893735
[161,] -0.508826270
[162,] -0.402183503
[163,] -0.519491197
[164,] -0.124911660
[165,] -0.263545954
[166,] -0.300871573
[167,] -0.439509122
[168,] 0.035052490
[169,] -0.028933821
[170,] -0.055594513
[171,] -0.530152870
[172,] -0.220889499
[173,] -0.279544973
[174,] -0.332866356
[175,] -0.402183503
[176,] -0.364857884
[177,] -0.402183503
[178,] -0.300871573
[179,] -0.178233043
[180,] -0.407514340
[181,] -0.231554426
[182,] -0.140907424
[183,] -0.268880045
[184,] -0.668790419
[185,] 0.136364419
[186,] -0.210224571
[187,] -0.082255204
[188,] -0.311536501
[189,] 0.131030328
[190,] -0.295540737
[191,] -0.039598749
[192,] -0.204893735
[193,] 0.019056725
[194,] -0.311536501
[195,] -0.471500651
[196,] -0.199562898
[197,] -0.076921113
[198,] -0.236885263
[199,] -0.172902207
[200,] -0.012938057
[201,] 0.067044018
[202,] -0.098250968
[203,] 0.019056725
[204,] -0.002273130
[205,] -0.066259440
[206,] -0.082255204
[207,] -0.108915896
[208,] 0.184351712
[209,] -0.146241515
[210,] -0.252884281
[211,] 0.008391798
[212,] 0.168355947
[213,] 0.115034564
[214,] 0.152360183
[215,] -0.306205664
[216,] 0.360311625
[217,] -0.034264658
[218,] -0.194228807
[219,] -0.199562898
[220,] 0.099038800
[221,] 0.232342258
[222,] -0.012938057
[223,] 0.227008167
[224,] -0.226223590
[225,] 0.344315861
[226,] -0.199562898
[227,] 0.131030328
[228,] 0.285663641
[229,] 0.099038800
[230,] 0.056382345
[231,] 0.243007186
[232,] -0.076921113
[233,] -0.167568116
[234,] 0.189685803
[235,] 0.163025111
[236,] 0.179020875
[237,] -0.002273130
[238,] -0.183563880
[239,] -0.594139181
[240,] -0.130242496
[241,] 0.120365401
[242,] 0.104369637
[243,] 0.381641480
[244,] 0.211012403
[245,] 0.301659405
[246,] -0.034264658
[247,] 0.488284246
[248,] 0.157691020
[249,] 0.525609866
[250,] 0.152360183
[251,] 0.376310644
[252,] 0.141695256
[253,] 0.290994478
[254,] 0.290994478
[255,] 0.322989260
[256,] 0.269667877
[257,] -0.332866356
[258,] 0.386972317
[259,] -0.028933821
[260,] 0.067044018
[261,] 0.344315861
[262,] 0.440293700
[263,] 0.402971335
[264,] 0.573597158
[265,] -0.135576587
[266,] 0.546936466
[267,] 0.264333786
[268,] 0.408302172
[269,] 0.328320097
[270,] 0.424297936
[271,] 0.541605630
[272,] 0.445627791
[273,] 1.069488625
[274,] 0.328320097
[275,] 0.434962863
[276,] 0.536274793
[277,] 0.125699492
[278,] 0.728230471
[279,] 0.514944938
[280,] 0.269667877
[281,] 0.221677331
[282,] 0.317655169
[283,] 0.493615083
[284,] 0.717565543
[285,] 0.424297936
[286,] 0.797547618
[287,] 0.893525457
[288,] 0.450958627
[289,] 0.317655169
[290,] 0.195016639
[291,] 0.440293700
[292,] 0.067044018
[293,] 0.642917559
[294,] 0.664244160
[295,] 0.562935485
[296,] 0.664244160
[297,] 0.477619319
[298,] 0.568266321
[299,] 0.536274793
[300,] 1.112145080
[301,] 0.402971335
[302,] 0.749560326
[303,] 0.434962863
[304,] 0.749560326
[305,] 0.568266321
[306,] 0.536274793
[307,] 0.637583468
[308,] 0.376310644
[309,] 0.424297936
[310,] 0.573597158
[311,] 0.456292718
[312,] 0.861533929
[313,] 0.418967099
[314,] 0.664244160
[315,] 0.957511767
[316,] 0.717565543
[317,] 0.482953410
[318,] 0.706900616
[319,] 0.600257849
[320,] 0.498949174
[321,] 0.776221017
[322,] 0.674909088
[323,] 0.706900616
[324,] 1.192127155
[325,] 0.941516003
[326,] 0.594927013
[327,] 0.808212545
[328,] 0.840204074
[329,] 0.973507531
[330,] 1.016167242
[331,] 1.000168223
[332,] 0.872198856
[333,] 0.232342258
[334,] 0.642917559
[335,] 1.106810989
[336,] 0.861533929
[337,] 0.701569779
[338,] 0.925520239
[339,] 0.930851076
[340,] 0.813543382
[341,] 0.957511767
[342,] 0.781551854
[343,] 0.797547618
[344,] 0.984172459
[345,] 0.658913323
[346,] 0.546936466
[347,] 1.133471681
[348,] 0.925520239
[349,] 0.578931249
[350,] 0.973507531
[351,] 0.781551854
[352,] 0.898859548
[353,] 1.234783611
[354,] 0.893525457
[355,] 1.005502314
[356,] 1.192127155
[357,] 0.850869001
[358,] 0.728230471
[359,] 0.968176695
[360,] 0.914855312
[361,] 0.706900616
[362,] 1.240114447
[363,] 1.277440066
[364,] 1.021498078
[365,] 0.877529693
[366,] 0.802881709
[367,] 1.005502314
[368,] 1.384082833
[369,] 1.416077615
[370,] 1.058823697
[371,] 1.480060671
[372,] 1.181462228
[373,] 1.282774157
[374,] 1.058823697
[375,] 0.968176695
[376,] 1.346757214
[377,] 1.138805772
[378,] 1.538716146
[379,] 1.218787847
[380,] 1.464064907
[381,] 1.389416924
[382,] 1.122810008
[383,] 1.245448538
[384,] 1.410743524
[385,] 1.517386291
[386,] 1.138805772
[387,] 1.101480153
[388,] 1.554711910
[389,] 1.682684531
[390,] 1.394747760
[391,] 1.314765685
[392,] 1.650689749
[393,] 1.544046982
[394,] 1.858644445
[395,] 1.432073379
[396,] 1.815987989
[397,] 1.618698220
[398,] 1.416077615
[399,] 1.970618047
[400,] 1.490725599
[401,] 1.773328279
[402,] 1.879971045
[403,] 2.221229199
[404,] 1.959953120
[405,] 2.061265050
[406,] 2.215898363
[407,] 2.045269286
[408,] 2.237224963
[409,] 1.917296664
[410,] 2.258554818
[411,] 2.343867730
[412,] 2.546488335
[413,] 2.679791793
[414,] 2.482505279
[415,] 2.578483117
[416,] 2.898411416
[417,] 2.994389255
[418,] -0.620799872
[419,] 1.234783611
[420,] -0.124911660
##Dengan menggunakan library dplyr lakukan semua perintah:
#1. {Select} Ingin dilakukan pemilihan variabel atau kolom dari data frame AHH pulau Sumatra berikut : AHH Wanita tahun 2020 dan AHH Pria tahun 2020.
#2. {Filter} Dengan menggunakan data yang telah difilter sebelumnya ingin dipilih cases dengan kondisi yang telah ditentukan yaitu AHH laki- laki yang lebih besar dari 67 tahun di provinsi Aceh dengan kode 1
#3. {Arrange} Ingin dilakukan pengurutan data berdasarkan data yang telah difilter pada no. 3
#4. {Summarise} Dengan menggunakan perintah summarise ingin dikeathui rata-rata AHH Wanita tahun 2020 di pulau Sumatra
#5. {Mutate} Ingin dilakukan perhitungan rasio antar AHH Wanita tahun 2020 dengan AHH pria tahun 2020
#6. {Group by} Ingin dilihat rata-rata AHH per provinsi
#7. {Piping} Ingin diperoleh data AHH Provinsi Aceh, dengan AHH wanita lebih besar dari 70 tahun dan AHH pria lebih besar dari 67 tahun, disusun berdasarkan AHH Wanita terkecil hingga terbesar, dan serta tambahan variabel yang menyatakan rasio AHH Wanita/AHH Pria tahun 2020
#8. {Join} Menggabungkan data tahun 2019 dan tahun 2020
a <- mean(dt$income)
b <- mean(dt$expenditure)
if (a > b) {
print("Rata-rata income lebih besar dari rata rata expenditure")
} else {
print("Rata-rata income lebih kecil dari rata rata expenditur")
}
## [1] "Rata-rata income lebih kecil dari rata rata expenditur"
ifelse (a > b, print("Rata-rata income lebih besar dari rata rata expenditure"), print("Rata-rata income lebih kecil dari rata rata expenditure"))
## [1] "Rata-rata income lebih kecil dari rata rata expenditure"
## [1] "Rata-rata income lebih kecil dari rata rata expenditure"
x <- mean(dt$math)
y <- sd(dt$math)
shapiro.test(dt$math)
##
## Shapiro-Wilk normality test
##
## data: dt$math
## W = 0.99366, p-value = 0.07594
## data dapat dianggap berdistribusi normal
#ingin diketahui besar peluang besar AHH wanita tahun 2017 yang lebih besar dari 67 dan kurang dari 70
hasil<-(pnorm(660,x,y) - pnorm(650,x,y))
Berdasarkan hasil pehitungan dapat diketahui bahwa besar peluang besarnya score math lebih besar dari 650 dan kurang dari 70 adalah 0.209428
library(dplyr)
#Select
dt<-data.frame(dt)
score.test<-dplyr::select(dt,school,county,grades,math,read)
head(score.test)
## school county grades math read
## 1 Sunol Glen Unified Alameda KK-08 690.0 691.6
## 2 Manzanita Elementary Butte KK-08 661.9 660.5
## 3 Thermalito Union Elementary Butte KK-08 650.9 636.3
## 4 Golden Feather Union Elementary Butte KK-08 643.5 651.9
## 5 Palermo Union Elementary Butte KK-08 639.9 641.8
## 6 Burrel Union Elementary Fresno KK-08 605.4 605.7
#Filter
score.cerdas<- filter(score.test, math>650, read>650 )
score.cerdas
## school county grades math read
## 1 Sunol Glen Unified Alameda KK-08 690.0 691.6
## 2 Manzanita Elementary Butte KK-08 661.9 660.5
## 3 Salida Union Elementary Stanislaus KK-08 650.7 651.7
## 4 Monte Rio Union Elementary Sonoma KK-08 651.8 651.9
## 5 Fullerton Elementary Orange KK-08 652.6 651.6
## 6 Santa Barbara Elementary Santa Barbara KK-08 653.7 650.9
## 7 South Fork Union Elementary Kern KK-08 651.9 653.1
## 8 Live Oak Elementary Santa Cruz KK-08 650.1 656.1
## 9 Menifee Union Elementary Riverside KK-08 653.1 653.7
## 10 Lakeside Union Elementary Kern KK-08 654.6 652.4
## 11 Whisman Elementary Santa Clara KK-08 651.5 655.6
## 12 McCabe Union Elementary Imperial KK-08 653.7 653.4
## 13 Lammersville Elementary San Joaquin KK-08 653.3 654.1
## 14 Lassen View Union Elementary Tehama KK-08 652.1 655.5
## 15 Loleta Union Elementary Humboldt KK-08 651.8 655.9
## 16 Junction Elementary Shasta KK-08 651.3 656.6
## 17 Rosemead Elementary Los Angeles KK-08 656.8 651.4
## 18 Grass Valley Elementary Nevada KK-08 650.6 657.8
## 19 Kernville Union Elementary Kern KK-08 653.5 655.1
## 20 Galt Joint Union Elementary Sacramento KK-08 656.5 652.7
## 21 Southside Elementary San Benito KK-08 655.5 654.2
## 22 Lakeside Union Elementary San Diego KK-08 656.2 653.5
## 23 Oakley Union Elementary Contra Costa KK-08 652.7 657.4
## 24 Berryessa Union Elementary Santa Clara KK-08 655.2 655.4
## 25 Kit Carson Union Elementary Kings KK-08 657.7 653.0
## 26 Sylvan Union Elementary Stanislaus KK-08 653.1 657.6
## 27 Oak View Union Elementary San Joaquin KK-08 657.6 653.2
## 28 North County Joint Union Elementary San Benito KK-08 659.8 651.6
## 29 Central Elementary San Bernardino KK-08 655.8 655.9
## 30 Pacheco Union Elementary Shasta KK-08 658.7 654.1
## 31 Chicago Park Elementary Nevada KK-08 655.2 657.8
## 32 Brisbane Elementary San Mateo KK-08 654.4 658.7
## 33 Central Union Elementary Kings KK-08 657.9 655.4
## 34 Happy Valley Union Elementary Shasta KK-08 651.9 661.5
## 35 Mark Twain Union Elementary Calaveras KK-08 650.2 663.4
## 36 San Rafael City Elementary Marin KK-08 656.9 656.7
## 37 Cajon Valley Union Elementary San Diego KK-08 656.4 657.6
## 38 Campbell Union Elementary Santa Clara KK-08 656.7 657.3
## 39 Browns Elementary Sutter KK-08 653.3 661.0
## 40 Guerneville Elementary Sonoma KK-08 650.9 664.2
## 41 San Bruno Park Elementary San Mateo KK-08 655.6 659.7
## 42 Antelope Elementary Tehama KK-08 655.3 660.2
## 43 Centralia Elementary Orange KK-06 660.5 655.1
## 44 Etiwanda Elementary San Bernardino KK-08 657.3 658.5
## 45 Wiseburn Elementary Los Angeles KK-08 659.0 657.0
## 46 Scotia Union Elementary Humboldt KK-08 652.7 664.0
## 47 Mountain View Elementary San Bernardino KK-08 662.5 654.7
## 48 Pleasant Valley Joint Union Elementary San Luis Obispo KK-06 656.3 661.3
## 49 Oak Grove Elementary Santa Clara KK-08 663.2 654.9
## 50 Pollock Pines Elementary El Dorado KK-08 656.2 662.1
## 51 Castaic Union Elementary Los Angeles KK-08 660.4 658.3
## 52 Bishop Union Elementary Inyo KK-08 656.0 662.8
## 53 Buellton Union Elementary Santa Barbara KK-08 658.8 660.0
## 54 Chawanakee Jt. Elementary Madera KK-08 658.8 660.8
## 55 Yreka Union Elementary Siskiyou KK-08 659.4 660.4
## 56 Alexander Valley Union Elementary Sonoma KK-06 658.4 661.7
## 57 Sundale Union Elementary Tulare KK-08 660.6 659.8
## 58 Three Rivers Union Elementary Tulare KK-08 652.8 667.8
## 59 Columbia Union Elementary Tuolumne KK-08 654.6 666.9
## 60 Westside Union Elementary Los Angeles KK-08 659.8 662.1
## 61 Ballico-Cressey Elementary Merced KK-08 661.6 661.1
## 62 Millbrae Elementary San Mateo KK-08 660.9 662.0
## 63 Evergreen Elementary Santa Clara KK-08 664.1 659.1
## 64 Harmony Union Elementary Sonoma KK-08 650.8 672.4
## 65 Panama Buena Vista Union Elementary Kern KK-08 663.6 660.1
## 66 Laguna Salada Union Elementary San Mateo KK-08 658.3 665.4
## 67 Sonora Elementary Tuolumne KK-08 661.0 662.7
## 68 Roseville City Elementary Placer KK-08 659.5 664.3
## 69 Gratton Elementary Stanislaus KK-08 661.3 662.5
## 70 Susanville Elementary Lassen KK-08 663.5 660.4
## 71 Bella Vista Elementary Shasta KK-08 661.7 663.1
## 72 Columbine Elementary Tulare KK-08 673.4 651.4
## 73 Hughes-Elizabeth Lakes Union Elementary Los Angeles KK-08 659.5 665.4
## 74 Mountain View Elementary Santa Clara KK-08 661.5 663.5
## 75 Sulphur Springs Union Elementary Los Angeles KK-06 663.4 661.7
## 76 Forestville Union Elementary Sonoma KK-08 655.7 669.4
## 77 Rosedale Union Elementary Kern KK-08 667.0 658.3
## 78 Columbia Elementary Shasta KK-08 663.0 662.4
## 79 Colfax Elementary Placer KK-08 658.4 667.1
## 80 Mt. Shasta Union Elementary Siskiyou KK-08 657.5 668.3
## 81 Piner-Olivet Union Elementary Sonoma KK-06 659.3 667.4
## 82 Bass Lake Joint Elementary Madera KK-08 662.6 664.3
## 83 Cutten Elementary Humboldt KK-06 666.8 660.2
## 84 Placerville Union Elementary El Dorado KK-08 661.3 666.4
## 85 Wright Elementary Sonoma KK-06 668.3 659.4
## 86 Evergreen Union Elementary Tehama KK-08 670.1 657.7
## 87 Old Adobe Union Elementary Sonoma KK-06 661.8 666.2
## 88 Wilmar Union Elementary Sonoma KK-06 659.3 668.7
## 89 Ackerman Elementary Placer KK-08 657.0 671.3
## 90 Santa Cruz City Elementary Santa Cruz KK-06 661.6 666.7
## 91 Arcata Elementary Humboldt KK-08 654.6 674.0
## 92 Alta Loma Elementary San Bernardino KK-08 665.4 663.4
## 93 Foresthill Union Elementary Placer KK-08 665.8 663.1
## 94 Mother Lode Union Elementary El Dorado KK-08 663.9 665.5
## 95 Ocean View Elementary Orange KK-08 665.8 663.7
## 96 Lake Elementary Glenn KK-08 662.3 667.6
## 97 San Mateo-Foster City Elementary San Mateo KK-08 664.0 665.9
## 98 Goleta Union Elementary Santa Barbara KK-06 663.4 666.8
## 99 Helendale Elementary San Bernardino KK-08 674.2 656.2
## 100 Petaluma City Elementary Sonoma KK-06 660.9 669.8
## 101 Sunnyvale Elementary Santa Clara KK-08 667.4 663.9
## 102 College Elementary Santa Barbara KK-08 661.5 670.3
## 103 La Mesa-Spring Valley San Diego KK-08 667.4 664.5
## 104 Huntington Beach City Elementary Orange KK-08 664.0 668.0
## 105 Solvang Elementary Santa Barbara KK-08 663.4 668.7
## 106 Soquel Elementary Santa Cruz KK-08 665.3 666.9
## 107 Capay Joint Union Elementary Glenn KK-08 660.4 671.9
## 108 Gravenstein Union Elementary Sonoma KK-08 661.3 671.0
## 109 Pleasant Valley Elementary Nevada KK-08 664.1 668.8
## 110 Pioneer Union Elementary Kings KK-08 661.9 671.2
## 111 Santee Elementary San Diego KK-08 669.5 663.7
## 112 Johnstonville Elementary Lassen KK-08 661.2 672.1
## 113 Pleasant Valley Elementary Ventura KK-08 665.8 667.5
## 114 Curtis Creek Elementary Tuolumne KK-08 671.3 662.1
## 115 Fort Jones Union Elementary Siskiyou KK-06 666.8 666.9
## 116 Mark West Union Elementary Sonoma KK-06 662.4 671.3
## 117 Alpine Union Elementary San Diego KK-08 666.6 667.7
## 118 Sebastopol Union Elementary Sonoma KK-08 664.6 669.8
## 119 Freshwater Elementary Humboldt KK-06 662.7 672.2
## 120 Norris Elementary Kern KK-08 667.9 667.0
## 121 Springville Union Elementary Tulare KK-08 666.0 669.2
## 122 Moreland Elementary Santa Clara KK-08 666.6 669.4
## 123 Maple Elementary Kern KK-08 675.7 660.5
## 124 Kings River-Hardwick Union Elementary Kings KK-08 671.0 665.8
## 125 Julian Union Elementary San Diego KK-08 664.5 672.7
## 126 Cardiff Elementary San Diego KK-06 668.5 668.8
## 127 Saucelito Elementary Tulare KK-08 669.1 668.5
## 128 Bonsall Union Elementary San Diego KK-08 671.6 666.2
## 129 Cypress Elementary Orange KK-06 672.4 665.5
## 130 Lowell Joint Elementary Los Angeles KK-08 672.1 666.1
## 131 Newhall Elementary Los Angeles KK-06 669.7 668.9
## 132 Lagunitas Elementary Marin KK-08 657.7 680.9
## 133 Cambrian Elementary Santa Clara KK-08 665.4 673.3
## 134 Richfield Elementary Tehama KK-08 674.1 664.6
## 135 Fieldbrook Elementary Humboldt KK-08 669.5 670.1
## 136 Dehesa Elementary San Diego KK-06 666.5 673.2
## 137 Cottonwood Union Elementary Shasta KK-08 670.7 669.2
## 138 Fruitvale Elementary Kern KK-08 670.8 669.2
## 139 Union Elementary Santa Clara KK-08 668.6 672.8
## 140 Fountain Valley Elementary Orange KK-08 671.3 671.2
## 141 Gold Oak Union Elementary El Dorado KK-08 668.0 674.6
## 142 Buckeye Union Elementary El Dorado KK-08 668.3 674.9
## 143 Rocklin Unified Placer KK-08 671.8 671.4
## 144 Gold Trail Union Elementary El Dorado KK-08 665.7 677.6
## 145 Hydesville Elementary Humboldt KK-08 663.6 679.8
## 146 Saugus Union Elementary Los Angeles KK-06 674.6 668.9
## 147 Loomis Union Elementary Placer KK-08 670.7 673.1
## 148 Placer Hills Union Elementary Placer KK-08 664.2 679.6
## 149 Dunham Elementary Sonoma KK-06 671.6 672.3
## 150 San Carlos Elementary San Mateo KK-08 668.0 676.1
## 151 Ready Springs Union Elementary Nevada KK-08 670.2 673.9
## 152 Coarsegold Union Elementary Madera KK-08 676.5 668.1
## 153 Cayucos Elementary San Luis Obispo KK-08 670.1 674.6
## 154 Richmond Elementary Lassen KK-08 672.2 672.7
## 155 Clay Joint Elementary Fresno KK-08 675.7 669.4
## 156 Waugh Elementary Sonoma KK-06 669.3 676.1
## 157 Two Rock Union Elementary Sonoma KK-06 667.0 679.1
## 158 Belmont-Redwood Shores Elementary San Mateo KK-08 671.5 675.0
## 159 Rescue Union Elementary El Dorado KK-08 670.5 676.1
## 160 Alta-Dutch Flat Union Elementary Placer KK-08 666.6 680.5
## 161 San Pasqual Union Elementary San Diego KK-08 676.6 670.5
## 162 Latrobe Elementary El Dorado KK-08 677.3 670.5
## 163 Union Hill Elementary Nevada KK-08 672.5 676.0
## 164 Twin Hills Union Elementary Sonoma KK-08 669.8 681.0
## 165 Pacific Union Elementary Humboldt KK-08 668.4 683.0
## 166 Douglas City Elementary Trinity KK-08 672.2 680.1
## 167 Pleasant Ridge Union Elementary Nevada KK-08 679.3 673.8
## 168 Newcastle Elementary Placer KK-08 679.9 673.3
## 169 Mesa Union Elementary Ventura KK-08 673.2 680.5
## 170 Weaverville Elementary Trinity KK-08 681.1 672.8
## 171 North Cow Creek Elementary Shasta KK-08 675.5 679.0
## 172 Nevada City Elementary Nevada KK-08 677.4 678.5
## 173 Jacoby Creek Elementary Humboldt KK-08 673.2 682.9
## 174 Fort Ross Elementary Sonoma KK-08 671.5 685.3
## 175 Encinitas Union Elementary San Diego KK-06 678.6 679.0
## 176 Dixie Elementary Marin KK-08 674.7 684.1
## 177 Lakeside Joint Elementary Santa Clara KK-06 682.2 676.8
## 178 Hermosa Beach City Elementary Los Angeles KK-08 676.2 683.1
## 179 Rincon Valley Union Elementary Sonoma KK-06 680.8 678.7
## 180 Washington Union Elementary Monterey KK-08 679.4 680.2
## 181 Bennett Valley Union Elementary Sonoma KK-06 674.4 685.7
## 182 Loma Prieta Joint Union Elemen Santa Clara KK-08 676.7 684.2
## 183 Kenwood Elementary Sonoma KK-06 679.8 682.8
## 184 Liberty Elementary Sonoma KK-06 681.8 680.8
## 185 Knights Ferry Elementary Stanislaus KK-08 674.7 688.5
## 186 Kentfield Elementary Marin KK-08 674.0 689.8
## 187 Ballard Elementary Santa Barbara KK-06 682.5 681.8
## 188 Oak Grove Union Elementary Sonoma KK-08 684.9 680.0
## 189 Ross Valley Elementary Marin KK-08 679.5 685.6
## 190 Mountain Elementary Santa Cruz KK-06 678.0 687.3
## 191 Burlingame Elementary San Mateo KK-08 684.3 682.4
## 192 Grant Elementary Shasta KK-08 682.3 684.5
## 193 Happy Valley Elementary Santa Cruz KK-06 688.2 680.4
## 194 Bonny Doon Union Elementary Santa Cruz KK-06 680.2 688.5
## 195 Walnut Creek Elementary Contra Costa KK-08 687.4 682.2
## 196 Hope Elementary Santa Barbara KK-06 683.7 686.2
## 197 Larkspur Elementary Marin KK-08 679.9 692.2
## 198 Cupertino Union Elementary Santa Clara KK-08 690.3 683.1
## 199 Pacific Elementary Santa Cruz KK-06 681.3 693.8
## 200 Los Gatos Union Elementary Santa Clara KK-08 686.6 691.6
## 201 Montecito Union Elementary Santa Barbara KK-06 688.6 693.5
## 202 Solana Beach Elementary San Diego KK-06 695.0 687.7
## 203 Menlo Park City Elementary San Mateo KK-08 690.1 693.7
## 204 Reed Union Elementary Marin KK-08 692.0 695.9
## 205 Mill Valley Elementary Marin KK-08 694.9 693.6
## 206 Lafayette Elementary Contra Costa KK-08 691.7 697.9
## 207 Del Mar Union Elementary San Diego KK-06 695.3 695.1
## 208 Woodside Elementary San Mateo KK-08 689.3 701.3
## 209 Moraga Elementary Contra Costa KK-08 695.7 697.4
## 210 Orinda Union Elementary Contra Costa KK-08 697.3 699.1
## 211 Hillsborough City Elementary San Mateo KK-08 701.1 695.4
## 212 Cold Spring Elementary Santa Barbara KK-06 703.6 693.3
## 213 Portola Valley Elementary San Mateo KK-08 699.9 698.3
## 214 Saratoga Union Elementary Santa Clara KK-08 701.7 698.9
## 215 Las Lomitas Elementary San Mateo KK-08 707.7 700.9
## 216 Los Altos Elementary Santa Clara KK-08 709.5 704.0
## 217 Plumas Elementary Yuba KK-08 676.5 667.9
## 218 Wheatland Elementary Yuba KK-08 651.0 660.5
#Arrange
score.math.urut<-arrange(score.cerdas,desc(math))
head(score.math.urut)
## school county grades math read
## 1 Los Altos Elementary Santa Clara KK-08 709.5 704.0
## 2 Las Lomitas Elementary San Mateo KK-08 707.7 700.9
## 3 Cold Spring Elementary Santa Barbara KK-06 703.6 693.3
## 4 Saratoga Union Elementary Santa Clara KK-08 701.7 698.9
## 5 Hillsborough City Elementary San Mateo KK-08 701.1 695.4
## 6 Portola Valley Elementary San Mateo KK-08 699.9 698.3
#Summarise
summarise(score.cerdas, mean_read = mean(read, na.rm = TRUE))
## mean_read
## 1 669.8826
#Mutate
ratio.math.read<- mutate(score.cerdas, ratio.math.read = math/read)
head(ratio.math.read)
## school county grades math read ratio.math.read
## 1 Sunol Glen Unified Alameda KK-08 690.0 691.6 0.9976866
## 2 Manzanita Elementary Butte KK-08 661.9 660.5 1.0021196
## 3 Salida Union Elementary Stanislaus KK-08 650.7 651.7 0.9984656
## 4 Monte Rio Union Elementary Sonoma KK-08 651.8 651.9 0.9998465
## 5 Fullerton Elementary Orange KK-08 652.6 651.6 1.0015347
## 6 Santa Barbara Elementary Santa Barbara KK-08 653.7 650.9 1.0043017
#Group by
summarise(group_by(score.cerdas,county), mean_math = mean(math,na.rm= TRUE), mean_read = mean(read,na.rm = TRUE))
## # A tibble: 43 x 3
## county mean_math mean_read
## <chr> <dbl> <dbl>
## 1 Alameda 690 692.
## 2 Butte 662. 660.
## 3 Calaveras 650. 663.
## 4 Contra Costa 685. 687.
## 5 El Dorado 666. 671.
## 6 Fresno 676. 669.
## 7 Glenn 661. 670.
## 8 Humboldt 663. 671.
## 9 Imperial 654. 653.
## 10 Inyo 656 663.
## # ... with 33 more rows
#piping
new_score <- score.cerdas%>% filter(grades=="KK-08" , math>680, read>680) %>% arrange(math) %>% mutate(ratio_score = math/read)
head(new_score)
## school county grades math read ratio_score
## 1 Grant Elementary Shasta KK-08 682.3 684.5 0.9967860
## 2 Burlingame Elementary San Mateo KK-08 684.3 682.4 1.0027842
## 3 Los Gatos Union Elementary Santa Clara KK-08 686.6 691.6 0.9927704
## 4 Walnut Creek Elementary Contra Costa KK-08 687.4 682.2 1.0076224
## 5 Woodside Elementary San Mateo KK-08 689.3 701.3 0.9828889
## 6 Sunol Glen Unified Alameda KK-08 690.0 691.6 0.9976866
mean(dt$income)
## [1] 15.31659
mean(dt$expenditure)
## [1] 5312.408
#join
new.dt<-dplyr::select(dt, X,school,grades,county,income,expenditure)
join.dt<- full_join(new.dt,score.cerdas, by = "school")
head(join.dt)
## X school grades.x county.x income expenditure
## 1 1 Sunol Glen Unified KK-08 Alameda 22.690001 6384.911
## 2 2 Manzanita Elementary KK-08 Butte 9.824000 5099.381
## 3 3 Thermalito Union Elementary KK-08 Butte 8.978000 5501.955
## 4 4 Golden Feather Union Elementary KK-08 Butte 8.978000 7101.831
## 5 5 Palermo Union Elementary KK-08 Butte 9.080333 5235.988
## 6 6 Burrel Union Elementary KK-08 Fresno 10.415000 5580.147
## county.y grades.y math read
## 1 Alameda KK-08 690.0 691.6
## 2 Butte KK-08 661.9 660.5
## 3 <NA> <NA> NA NA
## 4 <NA> <NA> NA NA
## 5 <NA> <NA> NA NA
## 6 <NA> <NA> NA NA