Learn R Programming

Pasha (version 0.99.21)

binVector: Divide a numeric vector in equal bins of signal

Description

Reduce the size of a numeric vector (typically large) to a more compact one by averaging the numeric values of 'binSize' (constant) consecutive cells.

Usage

binVector(piledValues, binSize)

Arguments

piledValues
A numeric vector
binSize
Size of the bins

Value

A numeric vector filled by the C function

Details

This function is typically used to represent piling scores for large chromosomes, specially if the scores have to be written in a file (WIG fixed step). When the last bin has fewer number of items, an average is also computed but only on the items available.

Examples

Run this code
# Create a vector of values and plot it
myValues <- sin(seq(1,10, length.out=300))*10
plot(x=1:length(myValues), myValues, type="b", pch=".", cex=2)

# Bin the vector by chunks of 20 points (compute the average value)
binnedValues <- binVector(myValues,20)

# Plot the binned value on top (with centered coordinates)
points(((x=1:length(binnedValues))*20)-10, 
         y=binnedValues, 
         col="blue",
         type="b",
         pch=5)
         

Run the code above in your browser using DataLab