Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a space in matrixStats for rowScale, colScale ? #255

Open
karoliskoncevicius opened this issue Apr 14, 2024 · 0 comments
Open

Is there a space in matrixStats for rowScale, colScale ? #255

karoliskoncevicius opened this issue Apr 14, 2024 · 0 comments

Comments

@karoliskoncevicius
Copy link

This issue is a question whether rowScale and colScale belongs in matrixStats.

In base there is scale(), however it is not convenient:

  1. it works on columns, so requires transposing to work on rows.
  2. it is quite slow.
X <- matrix(rnorm(100000000), ncol=1000)

system.time(scale(X))
  user  system elapsed                                                                                                                                                                                                               
17.748   2.032  19.825

The way I do scaling is now often like this:

system.time((X - colMeans(X)[col(X)]) / matrixStats::colSds(X)[col(X)])
 user  system elapsed                                                                                                                                                                                                               
5.057   0.878   5.949

But that is awkward to write, and still not efficient (means are calculated for both colMeans and colSds, col(X) is there twice).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant