weighted: A simple class for weighted data.

View source: R/table1.R

weightedR Documentation

A simple class for weighted data.

Description

A simple class for weighted data.

Usage

weighted(x, w)

Arguments

x

An atomic vector or data.frame.

w

An numeric vector of weights.

Value

An object identical to x but with the additional class weighted and a weights attribute.

Examples

x <- c(3.7, 3.3, 3.5, 2.8)
y <- c(1, 2, 1, 2)
w <- c(5, 3, 4, 1)

z <- weighted(x=x, w=w)
weights(z)
weights(z[2:3])  # Weights are preserved

d <- weighted(
  data.frame(
    x=x,
    y=y
  ),
  w
)

weights(d)
weights(d[[1]])
weights(d$x)
weights(subset(d, y==1))
lapply(split(d, d$y), weights)

benjaminrich/table1 documentation built on June 10, 2025, 10:43 p.m.