search for: numpiec

Displaying 1 result from an estimated 1 matches for "numpiec".

Did you mean: bumpier
2006 Apr 20
0
Breakdown a number [Broadcast]
I meant to send this to R-help, but it went to Gabor instead... This is my shot at it using diff(), assuming breaks is in non-decreasing order: chop <- function(x, breaks) { s <- sign(x - breaks) if (x <= breaks[1]) { ans <- x } else { numPieces <- sum(s == 1) ans <- diff(c(0, breaks[1:numPieces], x)) } ans } Some tests: > chop(1200, c(250, 800)) [1] 250 550 400 > chop(800, c(250, 800)) [1] 250 550 > chop(100, c(250, 800)) [1] 100 > chop(600, c(250, 800)) [1] 250 350 Andy From: Paul Roebuck > &gt...