Learn R Programming

table1 (version 1.5.1)

weighted: A simple class for weighted data.

Description

A simple class for weighted data.

Usage

weighted(x, w)

Value

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

Arguments

x

An atomic vector or data.frame.

w

An numeric vector of weights.

Examples

Run this code
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)

Run the code above in your browser using DataLab