This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

plot(cars)

Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.

Home-runs so far

HR_before <- c(11, 13, 12) # Average Number of Home-runs per season wanted wanted_HR <- 20 # Number of seasons n_seasons <- 4 # Needed Home-runs on season 4 x_4 <- n_seasons*wanted_HR - sum(HR_before) # Minimum number of Home-runs needed by Robert x_4

[1] 44

Robert’s performance

Robert_HRs <- c(11, 13, 12,44) # Find mean mean(Robert_HRs)

[1] 20

Find standard deviation

sd(Robert_HRs)

[1] 16.02082

Find the maximum number of home-runs during the four seasons period

max(Robert_HRs)

[1] 44

Find the minimum number of home-runs during the four seasons period

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

n_1 <- 10 n_2 <- 4 y_1 <- 72000 y_2 <- 84000 # Mean salary overall salary_ave <- (n_1y_1 + n_2y_2)/(n_1+n_2) salary_ave

[1] 75428.57

contract_length <- read.table(“allcontracts.csv”, header = TRUE, sep = “,”) contract_years <- contract_length$years

Mean

contracts_mean <- mean(contract_years) contracts_mean

Median

contracts_median <- median(contract_years) contracts_median

Find number of observations

contracts_n <- length(contract_years) # Find standard deviation contracts_sd <- sd(contract_years)

contracts_w1sd <- sum((contract_years - contracts_mean)/contracts_sd < 1)/ contracts_n # Percentage of observation within one standard deviation of the mean contracts_w1sd

[1] 0.8416834

Difference from empirical

contracts_w1sd - 0.68

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 3 sd

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 histogram

hist(contract_years,xlab = “Years Left in Contract”,col = “green”,border = “red”, xlim = c(0,8), ylim = c(0,225), breaks = 5)