Skip to content

frollmean partial argument #4968

@thatchersj

Description

@thatchersj

I'm not sure if this is a feature or a bug, however I was surprised by the behaviour of frollmean, which returns NA for the first n-1 values, even if fill = NA and na.rm = TRUE. This means that you get different results from manually pre-padding your data with NA. It would be good to get others' thoughts on this behaviour.

Examples

I expected the two lines in the following examples to return the same values, but they do not.

> frollmean(1:10, 2, na.rm = TRUE)
 [1]  NA 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5

> frollmean(c(NA, 1:10), 2, na.rm = TRUE)[-1]
 [1] 1.0 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5
> frollmean(1:10, 3, na.rm = TRUE)
 [1] NA NA  2  3  4  5  6  7  8  9

> frollmean(c(NA, NA, 1:10), 3, na.rm = TRUE)[-(1:2)]
 [1] 1.0 1.5 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0

Session Info

> sessionInfo()

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252 
[2] LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

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

other attached packages:
[1] data.table_1.14.0

loaded via a namespace (and not attached):
[1] compiler_4.0.3

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions