#Home-runs so far
HR_before<-c(11, 13, 12)
# Average Number of Home-runs per season wanted
Wanted_Homeruns<-20
#Number of seasons
n_seasons<-4
#20=(11+13+12+x)/4
#80-36=x
x_4<-n_seasons*Wanted_Homeruns-sum(HR_before)
x_4
[1] 44
Robert_HRs<-c(11, 13, 12,44)
mean(Robert_HRs)
[1] 20
sd(Robert_HRs)
[1] 16.02082
max(Robert_HRs)
[1] 44
min(Robert_HRs)
[1] 11
summary(Robert_HRs)
Min. 1st Qu. Median Mean 3rd Qu. Max.
11.00 11.75 12.50 20.00 20.75 44.00
Question 1
Soto_Walks<-c(79,108,41,145,135)
wanted_walks<-100
number_seasons<-6
#Needed Walks on season 6
walks_6<-number_seasons*wanted_walks-sum(Soto_Walks)
walks_6
[1] 92
Case Scenerio 2
n_1<-10
n_2<-4
y_1<-72000
y_2<-84000
#Mean Salary Overall
salary_ave<-(n_1*y_1+n_2*y_2)/(n_1+n_2)
salary_ave
[1] 75428.57
bp_1<-7
fp_1<-9
w_1<-102000
w_2<-91000
#Mean Salary Overall
w_salary_ave<-(bp_1*w_1+fp_1*w_2)/(bp_1+fp_1)
w_salary_ave
[1] 95812.5
getwd()
[1] "C:/Users/orgac/OneDrive/Documents"
contract_length<-read.csv("allcontracts.csv",header = TRUE, sep=",")
contract_years<-contract_length$years
contracts_mean<-mean(contract_years)
contracts_mean
[1] 3.458918
round(contracts_mean,digits=2)
[1] 3.46
#Median
contracts_median<-median(contract_years)
contracts_median
[1] 3
#Find the number of observations
contracts_n<-length(contract_years)
#Find the standard deviation
contracts_sd<-sd(contract_years)
contracts_sd
[1] 1.69686
contracts_w1sd<-sum((contract_years-contracts_mean)/contracts_sd<1)/contracts_n
#Percentage of observations within on sd from the mean
round(contracts_w1sd, digits=2)
[1] 0.84
#Difference from empirical
round(contracts_w1sd-0.68,digits=2)
[1] 0.16
#Within 2 sd
contracts_w2sd<-sum((contract_years-contracts_mean)/contracts_sd<2)/contracts_n
contracts_w2sd
[1] 1
#Difference from empirical
contracts_w2sd-0.95
[1] 0.05
#Within 3sd
contracts_w3sd<-sum((contract_years-contracts_mean)/contracts_sd<3)/contracts_n
contracts_w3sd
[1] 1
#Difference from empirical
contracts_w3sd-0.9973
[1] 0.0027
Create a Histogram
summary(cars)
speed dist
Min. : 4.0 Min. : 2.00
1st Qu.:12.0 1st Qu.: 26.00
Median :15.0 Median : 36.00
Mean :15.4 Mean : 42.98
3rd Qu.:19.0 3rd Qu.: 56.00
Max. :25.0 Max. :120.00
hist(contract_years,xlab = "Years Left in Contract",col = "pink",border = "black",
xlim = c(0,8),ylim = c(0,250),breaks=3)
boxplot(contract_years,main="Years Left in Contract",ylab="Years")
boxplot(contract_years,main="Years Left in Contract",ylab="Years",col = "lightblue", border="black",horizontal= FALSE)
Question 3
doubles<-read.table("doubles_hit.csv",header = TRUE,sep = ",")
doubles_hit<-doubles$doubles_hit
doubles_hit_mean<-mean(doubles_hit)
doubles_hit_mean
[1] 23.55
doubles_hit_median<-median(doubles_hit)
doubles_hit_median
[1] 23.5
doubles_hit_n<-length(doubles_hit)
doubles_hit_sd<-sd(doubles_hit)
doubles_hit_w1sd<-sum((doubles_hit-doubles_hit_mean)/doubles_hit_sd<1)/doubles_hit_n
doubles_hit_w1sd
[1] 0.79
#Difference from epmirical
doubles_hit_w1sd-0.68
[1] 0.11
doubles_hit_w2sd<-sum((doubles_hit-doubles_hit_mean)/doubles_hit_sd<2)/doubles_hit_n
doubles_hit_w2sd
[1] 1
#Difference from empirical
doubles_hit_w2sd-0.95
[1] 0.05
doubles_hit_w3sd<-sum((doubles_hit-doubles_hit_mean)/doubles_hit_sd<3)/doubles_hit_n
doubles_hit_w2sd
[1] 1
#Difference from empirical
doubles_hit_w3sd-0.9973
[1] 0.0027
Histogram
hist(doubles_hit,xlab="Number of Doubles", col = "lightgreen" ,border = "darkblue",
xlim = c(0,60),ylim = c(0,30),breaks=7)
boxplot(doubles_hit,main="Boxp[lot of Doubles Hit by Player",ylab="Doubles",
col = "lightgreen",border = "darkblue")