Learn R Programming

sjPlot (version 1.7)

weight2: Weight a variable

Description

This function weights the variable var by a specific vector of weights. It's an alternative weight calculation to weight, though weight usage is recommended. This function sums up all weights values of the associated categories of var, whereas the weight function uses a xtabs formula to weight cases. Thus, this function may return a value with a different length than that from var.

Usage

weight2(var, weights)

Arguments

Value

The weighted var.

See Also

weight

Examples

Run this code
v <- sample(1:4, 20, TRUE)
table(v)
w <- abs(rnorm(20))
table(weight2(v,w))

Run the code above in your browser using DataLab