Install package BSDA

install.packages("BSDA")

Load BSDA package

library(BSDA)

1 sample Z-test Default command line

z.test(x,alternative = "two.sided",mu = 0,sigma.x = NULL,conf.level = 0.95)
Consider the weight (g) of eggs laid by 40 chickens
3.3, 3.4, 3.5, 2.9, 3.2, 3.1, 3.3, 3.4, 3.5, 3.7, 3.6, 3.3, 2.8, 4.0, 2.9, 3.2, 
3.1, 3.1, 3.2, 3.3, 3.4, 3.1, 3.2, 3.3, 3.4, 3.0, 3.1, 3.2, 3.4, 3.5, 3.6, 3.7, 
3.5, 3.4, 3.6, 3.7, 3.4, 3.5, 3.4, 3.5
Test the null hypothesis that the population weights of eggs is 3.3 g

Fit data into command line

Compute the standard deviation from data and put into sigma.x

library(BSDA)
## Loading required package: lattice
## 
## Attaching package: 'BSDA'
## The following object is masked from 'package:datasets':
## 
##     Orange
x<-c(3.3, 3.4, 3.5, 2.9, 3.2, 3.1, 3.3, 3.4, 3.5, 3.7, 3.6, 3.3, 2.8, 4.0, 
     2.9, 3.2, 3.1, 3.1, 3.2, 3.3, 3.4, 3.1, 3.2, 3.3, 3.4, 3.0, 3.1, 3.2, 
     3.4, 3.5, 3.6, 3.7, 3.5, 3.4, 3.6, 3.7, 3.4, 3.5, 3.4, 3.5)
z.test(x,sigma.x=0.2480, alternative="two.sided",mu=3.3,conf.level=0.95)
## 
##  One-sample z-Test
## 
## data:  x
## z = 1.0838, p-value = 0.2784
## alternative hypothesis: true mean is not equal to 3.3
## 95 percent confidence interval:
##  3.265645 3.419355
## sample estimates:
## mean of x 
##    3.3425