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)
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.
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:
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:
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…
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With