• R语言学习——输入与输出


    导入数据:

    grades<-read.table("D:/ProgramData/test1.txt",sep=" ")

    求均值:mean()

    求方差:sd()

    保存数据:write.table(grades,"D:/ProgramData/test2.txt")

    > grades<-read.table("D:/ProgramData/test1.txt",sep="	")
    > 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")

     

     

     

     

     

  • 相关阅读:
    Centos7 Crontab
    Centos7 php-fpm root 运行,执行 kill 等系统命令
    Centos7 安装系统服务、开机自启动
    CentOS7 安装Python3,开发SocketIO 客户端
    Centos7.6 安装DNS服务器
    exerunexplorer.exe
    Web GIS 离线地图
    DataGridView中添加CheckBox列用于选择行
    Android WebView Demo
    上海华魏光纤传感科技有限公司 招聘 《.NET研发工程师》
  • 原文地址:https://www.cnblogs.com/caiyishuai/p/9729721.html
Copyright © 2020-2023  润新知