### Document

```地質統計：R語言教學

1/9

Sample(x,n,replace=FALSE,prob=NULL)
x=被抽取的母體物件
n=欲抽出的樣本數
replace=FALSE/TRUE，當TRUE時，抽出後放

prob=NULL，表示母體物件中各元素被抽出的

2/9

s=1:5
sample(s)
sample(s,3)
sample(s,3,replace=TRUE)
sample(s,3,replace=FALSE)
sample(s,3,replace=TRUE,prob=NULL
sample(s,3,replace=TRUE,prob=c(0.6,0.1,0.1,0.1,
0.1))
3/9

sample(letters,5)
students=c("徐小錦","余中鐸","謝阿志","李大

sample(students)
4/9
Uniform distribution
Uniform 語法：runif(n,a,b)

5/9
Normal distribution
Normal 語法：rnorm(n,μ,σ2 )

6/9
Normal distribution pdf與cdf繪製
curve(dnorm(x),from=-3.5,
to=3.5,xlab="x",ylab="pdf",main="N(0,1) pdf")
dnorm(0) #找出某點數值
curve(pnorm(x),from=-3.5,
to=3.5,xlab="x", ylab="cdf",main="N(0,1) cdf")
pnorm(0) #找出某點數值
7/9

Using R, plot the signals and variograms for the
following functions.

1.A=B+0.01*C
2.D=0.01*C
3.A=B+D
8/9

library(sp)
#讀取sp這個package
library(gstat)
#讀取gstat這個package
C=rnorm(601,mean=0,sd=1)
#取601個隨機變數，題目給定mean及sd值 C=rnorm(601,0,1)
D=C*0.01
#將各變數乘以0.01符合題目
X=seq(-3,3,0.01)
#從-3到3每隔0.01間隔取值，符合題目
B=cos((pi/2)*X)
#根據題目定義cos函數
A=B+D
#定義Z函數
write.table(A,"C:/Users/burton/Desktop/2014/A.csv",row.names=T,col.names=T,sep=",")
e=read.csv('C:/Users/burton/Desktop/2014/1A.csv') #讀取從Excel中所複製的值(x,y,z)定義成e1
coordinates(e)=~x+y
#將Excel中的x.y定義成座標
v=variogram(A~1,e,cutoff=10,width=0.05)
plot(v)
#給條件用來定義變異數圖形
#繪製變異數圖形

plot(X,A)
#繪製函數圖形
9/9
```