导入数据:
grades<-read.table("D:/ProgramData/test1.txt",sep="\t")
求均值:mean()
求方差:sd()
保存数据:write.table(grades,"D:/ProgramData/test2.txt")
> grades<-read.table("D:/ProgramData/test1.txt",sep="\t") > grades V1 V2 V3 V4 V5 V6 V7 1 编号 1.00 2.0 3.00 4.0 5.00 6.00 2 身高m 1.75 1.8 1.65 1.9 1.74 1.91 3 体重kg 60.00 72.0 57.00 90.0 95.00 72.00 > data1<-as.matrix(grades) > data1 V1 V2 V3 V4 V5 V6 V7 [1,] "编号" " 1.00" " 2.0" " 3.00" " 4.0" " 5.00" " 6.00" [2,] "身高m" " 1.75" " 1.8" " 1.65" " 1.9" " 1.74" " 1.91" [3,] "体重kg" "60.00" "72.0" "57.00" "90.0" "95.00" "72.00" > data2<-as.numeric(data1[2,2:7]) > data2 [1] 1.75 1.80 1.65 1.90 1.74 1.91 > mean1=mean(data2) > mean1 [1] 1.791667 > data3<-as.numeric(data1[3,2:7]) > data3 [1] 60 72 57 90 95 72 > mean2=mean(data3) > mean2 [1] 74.33333
> grades[1,8]="mean" > grades[2,8]=mean1 > grades[3,8]=mean2 > grades V1 V2 V3 V4 V5 V6 V7 V8 1 编号 1.00 2.0 3.00 4.0 5.00 6.00 mean 2 身高m 1.75 1.8 1.65 1.9 1.74 1.91 1.79166666666667 3 体重kg 60.00 72.0 57.00 90.0 95.00 72.00 74.3333333333333
> sd1=sd(data2) > sd2=sd(data3) > grades[1,9]="sd" > grades[2,9]=sd1 > grades[3,9]=sd2 > grades V1 V2 V3 V4 V5 V6 V7 V8 1 编号 1.00 2.0 3.00 4.0 5.00 6.00 mean 2 身高m 1.75 1.8 1.65 1.9 1.74 1.91 1.79166666666667 3 体重kg 60.00 72.0 57.00 90.0 95.00 72.00 74.3333333333333 V9 1 sd 2 0.100282933077701 3 15.4229266569827
> write.table(grades,"D:/ProgramData/test2.txt")