If necessary, install the package samplingbook.

install.packages("samplingbook")

Following along Example 5 in Section 9.2, suppose we want to estimate the mean miles per gallon within 0.5 miles per gallon with 95% confdience. To calculate the minimum sample size needed, use the following command:

sample.size.prop(e = margin of error, S = sample standard deviation, level = level of confidence)

Note The S must be capitalized.

library(samplingbook)
sample.size.mean(e = 0.5, S = 2.38, level = 0.95)
## 
## sample.size.mean object: Sample size for mean estimate
## Without finite population correction: N=Inf, precision e=0.5 and standard deviation S=2.38
## 
## Sample size needed: 88

A sample size of 88 results in an interval estimate of the population mean mpg of a 2014 Toyota Camry with a margin of error of 0.5 mpg with 95% confidence.