R/wpct.r

Defines functions wpct

Documented in wpct

wpct <- function(x, weight=NULL, na.rm=TRUE, ...){
  if(is.null(weight)){
    weight <- rep(1, length(x))
  }
  y <- wtd.table(x, weight, na.rm=na.rm, ...)$sum.of.weights/sum(wtd.table(x, weight, na.rm=na.rm, ...)$sum.of.weights)
  names(y) <- wtd.table(x, weight, na.rm=na.rm, ...)$x
  z <- as.vector(y)
  names(z) <- names(y)
  if(is.logical(x))
    z <- rev(z)
  z
}

Try the weights package in your browser

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

weights documentation built on June 11, 2021, 1:06 a.m.