Equivalent to rowMeans() for min()

前端 未结 6 1452
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 10:40

I have seen this question being asked multiple times on the R mailing list, but still could not find a satisfactory answer.

Suppose I a matrix m

6条回答
  •  难免孤独
    2020-12-05 11:08

    library("sos")
    findFn("rowMin")
    

    gets a hit in the Biobase package, from Bioconductor ...

    source("http://bioconductor.org/biocLite.R")
    biocLite("Biobase")
    
    m <- matrix(rnorm(10000000), ncol=10)
    system.time(rowMeans(m))
    ##   user  system elapsed 
    ##  0.132   0.148   0.279 
    system.time(apply(m,1,min))
    ##   user  system elapsed 
    ## 11.825   1.688  13.603
    library(Biobase)
    system.time(rowMin(m))
    ##    user  system elapsed 
    ##  0.688   0.172   0.864 
    

    Not as fast as rowMeans, but a lot faster than apply(...,1,min)

提交回复
热议问题