[R] Breakdown a number

Paul Roebuck roebuck at mdanderson.org
Wed Apr 19 15:41:19 CEST 2006


Isn't there a builtin method for doing this and, if so,
what is it called?

        breakdown <- function(whole) {
            breaks <- c(250, 800)
            pieces <- integer(length(breaks) + 1)
            if (whole > breaks[2]) {
                pieces[3] <- whole - breaks[2]
                whole <- breaks[2]
            }
            if (whole > breaks[1]) {
                pieces[2] <- whole - breaks[1]
                whole <- breaks[1]
            }
            pieces[1] <- whole

            return(pieces)
        }

breakdown(1200)	# 250 550 400

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)




More information about the R-help mailing list