# 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