R/D2.R

Defines functions D2

D2 <-
function(size, newSize, grpIDs, grpSize, groups, data){
sumGrpDist <- unlist( lapply( 1:length(grpIDs), function(i){
tmp<- mean( daisy(data[groups==grpIDs[i],]) * grpSize[i] )
if(is.nan(tmp))
tmp <- 0
return(tmp)
} ))

sumDist <- sum(sumGrpDist)
newGrpSizes<- unlist (lapply( 1: length(grpIDs), function(i){
newGrpSize <- round( newSize * (sumGrpDist[i] / sumDist) )
if(newGrpSize == 0)
newGrpSize <- 1
return(newGrpSize)
}) )

return(newGrpSizes)
}

Try the ccChooser package in your browser

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

ccChooser documentation built on May 1, 2019, 10:56 p.m.