第一题:
1.将下面数据保存到“c:\height.txt”,备注:这里的数据没有用源数据,直接EXCEL生成了随机数拷贝到txt中
206
211
236
234
194
192
196
213
231
233
249
208
181
228
193
214
195
231
208
204
230
223
194
234
189
228
219
193
185
188
2.R代码
height<-read.table("c:/height.txt",header=FALSE)
stem(height$V1)#注意这里的height为list,直接调用stem没办法输出
3.output
The decimal point is 1 digit(s) to the right of the |
18 | 1589
19 | 2334456
20 | 4688
21 | 1349
22 | 388
23 | 0113446
24 | 9
第二题:
#93,62,51,93,75,82,93,62,65,51
a<-c(93,62,51,93,75,82,93,62,65,51)
#a的均值
a_mean<-mean(a)
b<-sort(a)
#a的中位数
a_zhong<-ifelse(length(b)%%2,b[length(b)/2+1],(b[length(b)/2]+b[length(b)/2+1])/2)
a_cha<-abs(a-a_mean)
#a的极差
a_ji<-max(a_cha)
#a的样本方差
a_var<-var(a)
#a的标准差
a_sd<-sd(a)
#a的众数
a_zong_shu<-names(which.max(table(a)))
a<-c(2500,1000,500,800,400,600)
names(a)<-c("食品","服装","出行","教育","医疗","其他")
pie(a)