File: moving.block.Rd

package info (click to toggle)
r-cran-animation 2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,268 kB
  • sloc: javascript: 873; sh: 15; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 2,178 bytes parent folder | download
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/moving.block.R
\name{moving.block}
\alias{moving.block}
\title{Cycle through an R object and plot each subset of elements}
\usage{
moving.block(dat = runif(100), block, FUN, ...)
}
\arguments{
\item{dat}{a numeric vector or two-column matrix}

\item{block}{block length (i.e. how many elements are to be plotted in each
step)}

\item{FUN}{a plot function to be applied to the subset of data}

\item{\dots}{other arguments passed to \code{FUN}}
}
\value{
\code{NULL}
}
\description{
For a long numeric vector or matrix (or data frame), we can plot only a
subset of its elements to take a closer look at its structure. With a moving
``block'' from the beginning to the end of a vector or matrix or any R
objects to which we can apply \code{subset}, all elements inside the block
are plotted as a line or scatter plot or any customized plots.
}
\details{
For a vector, the elments from \code{i + 1} to \code{i + block} will be
plotted in the i-th step; similarly for a matrix or data frame, a (scatter)
plot will be created from the \code{i + 1}-th row to \code{i + block}-th row.

However, this function is not limited to scatter plots or lines -- we can
customize the function \code{FUN} as we wish.
}
\note{
There will be \code{ani.options('nmax')} image frames created in the
  end. Ideally the relationship between \code{ani.options('nmax')} and
  \code{block} should follow this equality: \code{block = length(x) -
  ani.options('nmax') + 1} (replace \code{length(x)} with \code{nrow(x)} when
  \code{x} is a matrix). The function will compute \code{block} according to
  the equality by default if no block length is specified.

  The three arguments \code{dat}, \code{i} and \code{block} are passed to
  \code{FUN} in case we want to customize the plotting function, e.g. we may
  want to annonate the x-axis label with \code{i}, or we want to compute the
  mean value of \code{dat[i + 1:block]}, etc. See the examples below to learn
  more about how to make use of these three arguments.
}
\references{
Examples at \url{https://yihui.org/animation/example/moving-block/}
}
\author{
Yihui Xie
}