Question

Use knitr to produce at least 3 examples

generate 100 random numbers and make a plot

##randomly generate 100 numbers from the normal distribution(with mean=0,sd=1)
rs=rnorm(100,mean=0,sd=1)
##plot the random numbers
plot(rs)

we can get the $\bar{rs}=$ r mean(rs) and the variance $S^2=$ r var(rs).

generate 100 numbers and make a table

##generate 100 random numbers from the discrete distribution with prob=c(0.2,0.3,0.5)
x=sample(1:3,100,replace=TRUE,prob=c(0.2,0.3,0.5))
##table the 100 numbers
xt=table(x)
xt

and the relative frequency of 1,2,3 are r xt/100.

cite an image in the file

fig



hudie-lab/SC19036 documentation built on Jan. 2, 2020, 8:45 p.m.