colMax is not exported from the xcms package
1
0
Entering edit mode
Habil Zare ▴ 200
@habil-zare-7836
Last seen 5 months ago
United States/Austin Area

The colMax() function from the xcms package is very useful and even has good documentation, but why is it not exported?! Are there alternatives to "Find row and column maximum values for numeric arrays"?


library(xcms)
a1 <- array(1:(2*3*5),dim=c(5,3,2))
xcms:::colMax(a1)
     [,1] [,2]
[1,]    5   20
[2,]   10   25
[3,]   15   30
colMax(a1)
Error in colMax(a1) : could not find function "colMax"
?colMax


sessionInfo()
R Under development (unstable) (2021-01-28 r79891)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats4    parallel  stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
[1] xcms_3.13.8         MSnbase_2.17.7      ProtGenerics_1.23.9
[4] S4Vectors_0.29.9    mzR_2.25.5          Rcpp_1.0.6         
[7] Biobase_2.51.0      BiocGenerics_0.37.1 BiocParallel_1.25.5
xcms • 1.3k views
ADD COMMENT
0
Entering edit mode
Mike Smith ★ 6.5k
@mike-smith
Last seen 12 hours ago
EMBL Heidelberg

I haven't looked at the xcms implementation, but for your example could achieve this with apply() and max() performed over the 2nd and 3rd dimensions e.g.

> apply(a1, MARGIN = c(2,3), FUN = max)
     [,1] [,2]
[1,]    5   20
[2,]   10   25
[3,]   15   30
ADD COMMENT
0
Entering edit mode

xcms implemented it in c, which is 50 times faster than apply():

> a2 <- array(1:(10^7*3*5),dim=c(5,3,10^7))
> system.time(xcms:::colMax(a2))
   user  system elapsed 
  1.086   0.524   1.614 
> system.time(apply(a2, MARGIN = c(2,3), FUN = max))
   user  system elapsed 
 51.347   3.386  54.776 
ADD REPLY

Login before adding your answer.

Traffic: 415 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6