Learn R Programming

sjmisc (version 1.0.2)

weight: Weight a variable

Description

This function weights the variable var by a specific vector of weights.

Usage

weight(var, weights)

Arguments

var
The (unweighted) variable
weights
A vector with same length as var, which contains weight factors. Each value of var has a specific assigned weight in weights.

Value

  • The weighted var.

See Also

weight2

Examples

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

Run the code above in your browser using DataLab