美文网首页
rowmeans():Use R!

rowmeans():Use R!

作者: 淡水鱼Ada | 来源:发表于2019-12-04 20:54 被阅读0次
    >C1<-c(3,2,4,4,5)
    > C2<-c(3,7,3,4,5)
    > C3<-c(5,4,3,6,3)
    > DF<-data.frame(ID=c("A","B","C","D","E"),
    C1=C1,C2=C2,C3=C3)
    > DF
      ID C1 C2 C3
    1  A  3  3  5
    2  B  2  7  4
    3  C  4  3  3
    4  D  4  4  6
    5  E  5  5  3
    

    计算每行的均值

    > data.frame(ID=DF[,1], Means=rowMeans(DF[,-1]))
      ID    Means
    1  A 3.666667
    2  B 4.333333
    3  C 3.333333
    4  D 4.666667
    5  E 4.333333
    

    来源:https://stackoverflow.com/questions/10945703/calculate-row-means-on-subset-of-columns

    相关文章

      网友评论

          本文标题:rowmeans():Use R!

          本文链接:https://www.haomeiwen.com/subject/oifrgctx.html