summarise_along_walk | R Documentation |
This function summarises every n numbers in a vector.
summarise_along_walk(vec, every, summarise = sum, na.rm = FALSE, ...)
vec |
A numeric vector. |
every |
An integer that defines the step length of the walk over the vector. |
summarise |
A function that summarises the numbers in each step. |
na.rm |
A logical value that defines whether or not to remove NAs. |
... |
Additional arguments passed to |
The function returns a numeric vector.
This function is a slight modification of the code provided here: https://stackoverflow.com/questions/43635846/calculating-mean-for-every-n-values-from-a-vector.
## Not run:
x <- c(rep(1, 10), rep(2, 10))
summarise_along_walk(x, every = 10)
x <- c(mean(10, 5), mean(100, 5))
summarise_along_walk(x, every = 10, summarise = mean)
x <- c(x, NA)
summarise_along_walk(x, every = 10, summarise = mean, na.rm = TRUE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.