Q:

Sample mean Margin of Error and C.I

I have data on the mean assembly costs for the first n=36 days of production. It is assumed that the following data follows a Normal distribution:
AC <- c(345.35, 346.25, 351.65, 341.75, 347.00, 288.95, 342.50, 330.35, 326.85, 341.25,
        329.55, 327.85, 329.00, 363.50, 341.25, 329.90, 324.50, 338.90, 331.60, 333.80,
        343.45, 352.35, 351.95, 289.90, 331.75, 336.75, 341.65, 356.75, 330.95, 360.25,
        297.25, 348.95, 324.50, 338.90, 331.60, 333.80)

I want to do an estimation of the mean by establishing a margin of error and a confidence interval, using a 95% confidence-level.
I want to code this in R. I have already found the following statistics in R. 
 mean(AC);
 ## [1] 335.625
 var(AC);
 ## [1] 278.8489
 sd(AC);
 ## [1] 16.69877

A:

You say you assume that your data follows a Normal distribution. We calculated the mean and standard deviation of our data, and we have n=36 observations.
The mean of the recorded data is said to follow a student t-distribution with n-1 degrees of freedom and standard deviation equal to sd(AC) / sqrt(n). 
If we now manage to figure out the critical t-value for a 95% confidence interval and 35 degrees of freedom, we can use the standard formula: sample_mean ± critical-value*standard_deviation, which is equivalent to sample_mean± margin_of_error`
n <- length(AC)

mean_X   <- mean(AC)
std_dev  <- sd(AC)/sqrt(n)
crit_val <- qt(0.975, df=35)    

margin_of_error <- std_dev * crit_val

mean_X - margin_of_error   # 329.9749
mean_X + margin_of_error   # 341.2751

So your 95% confidence interval is [329.97, 341.28]. 

