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

colMeans2 does row wise calculation with newer R versions #247

Open
itsme24 opened this issue Feb 21, 2024 · 1 comment
Open

colMeans2 does row wise calculation with newer R versions #247

itsme24 opened this issue Feb 21, 2024 · 1 comment

Comments

@itsme24
Copy link

itsme24 commented Feb 21, 2024

Dear all,
I get a weird behaviour with R version 4.3.1 which does not calculate the colMeans2 any more but does a row-wise calculation. This is not the case with e.g. R 4.2.2.

I couldn't figure out if and where the feature in the c-code this is coming from.
I haven't found another colFunc where I found this row-wise result.

print(R.version.string)

a<- data.table(rebalancing=rep(c(1L,NA), 5) , coverage=rep(c(1.0,0.5,0.9,0.5,0.8),2), b='b')

print('base')
print(a[, colMeans(cbind(coverage*rebalancing), na.rm=T) , by='b'] )

print('matrixStats')
a[, matrixStats::colMeans2(cbind(coverage*rebalancing), na.rm=T) , by='b']

image

@yaccos
Copy link
Contributor

yaccos commented Feb 22, 2024

I have tried out your example with R 4.3.2 and matrixStats 1.2.0. When running it there is no difference between the output using base::colMeans() and matrixStats::colMeans2(). For this particular example, it would be more convenient to writea[, mean(coverage*rebalancing, na.rm=T), by='b'], eliminating the need for creating a one-column matrix.

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

2 participants