> x1<-c(2,2,4,3,2,1,6,5,2,9,9,7,9,0,6,5,4,3)
> mean(x1)
[1] 4.388889
> mean(x1,trim=3,na.rm=FLASE)
Error in mean.default(x1, trim = 3, na.rm = FLASE) : 找不到对象'FLASE'
> mean(x1,trim=3,na.rm=FALSE)
[1] 4
> sum(x1,trim=9)
[1] 88
> sum(x1)
[1] 79
> x1<-c(2,2,4,3,2,1)
> mean(x1)
[1] 2.333333
> sum(x1)
[1] 14
> sum(x1,trim=2)
[1] 16
> mean(x1,trim=1)
[1] 2
> mean(x1,trim=3)
[1] 2
> x1<-c(2,2,4,3,2,1,6,5,2,9,9,7,9,0,6,5,4,3)
> x1
[1] 2 2 4 3 2 1 6 5 2 9 9 7 9 0 6 5 4 3
> sort(x1)
[1] 0 1 2 2 2 2 3 3 4 4 5 5 6 6 7 9 9 9
> order(x1)
[1] 14 6 1 2 5 9 4 18 3 17 8 16 7 15 12 10 11 13
> median(x1)
[1] 4
> median(x1,na.rm=TRUE)
[1] 4
> quantile(x1,probs=seq(0,1,0.25),na.rm=FALSE)
0% 25% 50% 75% 100%
0 2 4 6 9
> quantile(x1)
0% 25% 50% 75% 100%
0 2 4 6 9
> var(x1)
[1] 7.898693
> sd(x1)
[1] 2.810461
> cv<-100*sd(x1)/mean(x1);cv
[1] 64.03583
> cv<-100*sd(x1)/mean(x1)
> #cv是求变异系数
> cv
[1] 64.03583
> #css是求孝正平方和
> css<-sum((x-mean(x))^2)
错误: 找不到对象'x'
> css<-sum((x1-mean(x1))^2)
> css
[1] 134.2778
> #uss是求未孝正平方和
> uss<-sum(x1^2)
> uss
[1] 481
> #R求极差
> R<-max(x1)-min(x1)
> R
[1] 9
> #半极差
> R1<-quantile(x1,0.75)-quantile(x1,0.25)
> R1
75%
4
> #样本标准误
> sm<-sd(x1)/sqrt(length(x1)
+ sm<-sd(x1)/sqrt(length(x1))
错误: unexpected symbol in:
"sm<-sd(x1)/sqrt(length(x1)
sm"
> Sm<-sd(x1)/sqrt(length(x1))
> Sm
[1] 0.6624321
> #样本峰度系数SK
> n<-length(x1)
> m<-length(x1)
> s<-sd(x1)
> sk<-n/((n-1)*(n-2)*sum((x1-m)^3)/s^3
+ sk<-n/((n-1)*(n-2))*sum((x1-m)^3)/s^3
错误: unexpected symbol in:
"sk<-n/((n-1)*(n-2)*sum((x1-m)^3)/s^3
sk"
> sk<-n/((n-1)*(n-2)*sum((x1-m)^3)/s^3
+
+ sk<-n/((n-1)*(n-2)*sum((x1-m)^3)/s^3
错误: unexpected symbol in:
"
sk"
> sk<-n/((n-1))*(n-2)*sum((x1-m)^3)/s^3
> sk
[1] -38718.49
> #偏度系数ku
> ku<-((n*(n+1))/((n-1)*(n-2)*(n-3))*sum((x1-m)^4)/s^4-(3*(n-1)^2)/((n-2)*(n-3)))
> ku
[1] 1019.694
df<-data.frame(Name=c("A","B","C","D","E"),Sex=c("F","F","M","M","M")
+ ,Age=c(12,13,14,15,12),Height=c(56.5,58.7,62.4,60.2,72),Weigt=c(80,84,90,72,99.5))
> write.table(df,file="foo.txt")
> #write.table函数试讲数据框写成纯文本形式的数据文件#
> write.csv(df,file="foo.csv")
> df
Name Sex Age Height Weigt
1 A F 12 56.5 80.0
2 B F 13 58.7 84.0
3 C M 14 62.4 90.0
4 D M 15 60.2 72.0
5 E M 12 72.0 99.5