Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`cummean()` function from dplyr not providing results as expected

Tags:

r

dplyr

I just want to make sure I am understanding this correctly. So I have this small vector x where the long(er) way is giving me the results as expected but dplyr cummean() is not. I am using version 1.0.0. I have tried reading documentation and searching other guides online but it's almost non-existant. Is this what is expected of cummean()? If yes, what are the values that go into this function for the resulting output?

library(tidyverse)
x <- 1:5

# long(er) way
cumsum(x) / seq_along(x)
#> [1] 1.0 1.5 2.0 2.5 3.0

# dplyr cummean()
cummean(x)
#> [1] 1.000000 1.000000 1.333333 1.750000 2.200000

Created on 2020-05-31 by the reprex package (v0.3.0)

like image 923
cropgen Avatar asked May 31 '20 17:05

cropgen


People also ask

What is the difference between Cumall and cumany function?

Similar to the cumall function, we can apply the cumany function: The cumany function is the cumulative version of the any function and tests whether at least one vector element is TRUE. The third function I want to show you is the cummean function.

What is the cumany function in MATLAB?

The cumany function is the cumulative version of the any function and tests whether at least one vector element is TRUE. The third function I want to show you is the cummean function. The cummean function is applied to numeric vectors. Let’s create such a vector first: Now, we can apply the cummean command as follows:

What is the cumany function in statistics?

The cumany function is the cumulative version of the any function and tests whether at least one vector element is TRUE. The third function I want to show you is the cummean function. The cummean function is applied to numeric vectors. Let’s create such a vector first:

What is the Cumall function in R?

As you can see based on the RStudio console output, the cumall function is a cumulative version of the all function. First, the cumall function checks whether the first element is TRUE; then it checks whether the first AND the second element are TRUE; then it checks whether the first, the second AND the third element are TRUE and so on…


1 Answers

Just to close this question:

This was a bug in dplyr 1.0.0 which has been solved, see GitHub tidyverse/dplyr #5325.

This error does not encounter in dplyr version 1.0.2, currently on CRAN

like image 155
Thomas Avatar answered Nov 06 '22 02:11

Thomas