-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummarise_along_walk.Rd
40 lines (35 loc) · 1.15 KB
/
summarise_along_walk.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sims.R
\name{summarise_along_walk}
\alias{summarise_along_walk}
\title{Summarise every n numbers in a vector}
\source{
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.
}
\usage{
summarise_along_walk(vec, every, summarise = sum, na.rm = FALSE, ...)
}
\arguments{
\item{vec}{A numeric vector.}
\item{every}{An integer that defines the step length of the walk over the vector.}
\item{summarise}{A function that summarises the numbers in each step.}
\item{na.rm}{A logical value that defines whether or not to remove NAs.}
\item{...}{Additional arguments passed to \code{summarise}.}
}
\value{
The function returns a numeric vector.
}
\description{
This function summarises every n numbers in a vector.
}
\examples{
\dontrun{
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)
}
}
\keyword{internal}