Learn R Programming

pegas (version 0.11)

sw: Sliding Windows

Description

Applies a function over a matrix using sliding windows. sw is a generic function with a method for "DNAbin" matrices.

Usage

sw(x, width, step, ...)
# S3 method for DNAbin
sw(x, width = 100, step = 50, FUN = GC.content,
   rowAverage = FALSE, quiet = TRUE, ...)

Arguments

x

a matrix.

width

an integer giving the window width.

step

an integer giving the step separating successive windows.

FUN

the function to be applied to the windows.

rowAverage

a logical value: if TRUE, FUN is applied over all rows of x; if FALSE (the default) FUN is applied to each row of x.

quiet

a logical value: if FALSE, the progress of the calculations is printed.

further arguments passed to and from methods.

Value

a matrix or a vector (if rowAverage = TRUE).

Details

FUN should return a single value, and x should be a matrix.

Examples

Run this code
# NOT RUN {
data(woodmouse)
sw(woodmouse)
sw(woodmouse, 200, 200)
sw(woodmouse, 200, 200, rowAverage = TRUE)

## to get the proportions of G:
foo <- function(x) base.freq(x)["g"]
sw(woodmouse, 200, 200, FUN = foo, rowAverage = TRUE)
# }

Run the code above in your browser using DataLab