inst/Examples/binaryCount.R

binaryCount <- function(nodes, leafValues) {
    nL <- length(leafValues)
    nN <- nrow(nodes)
    left <- nodes[,1]; right <- nodes[, 2]
    
    left <- ifelse(left<0, -left, left + nL)
    right <- ifelse(right<0, -right , right + nL)
    
    count <- c(leafValues, rep(NA, nN))
    
    while(any(is.na(count)))
        count <- c(leafValues, count[left] + count[right])

    count[-seq(length=nL)]
}

Try the SoDA package in your browser

Any scripts or data that you put into this service are public.

SoDA documentation built on Oct. 28, 2020, 9:07 a.m.