Learn R Programming

RCPA3 (version 1.3.1)

wtd.quantile: Finds the Quantile Values of Variable With Option for Weights

Description

Takes in variable and calculates desired quantile values, works with sampling weights. Makes use of the wtd.quantile function from the Hmisc package. See wtd.stats documentation for details.

Usage

wtd.quantile(x, w = NULL, data, q = c(5, 10, 25, 50, 75, 90, 95),
  digits = 3, ...)

Value

Returns quantile values of a variable, a vector of numeric values.

Arguments

x

A variable (must be numeric), should be in dataset$var form unless dataset specified in optional data argument.

w

(Optional) Sampling weights of variable, must be numeric; should be in dataset$weightvar form unless dataset specified in optional data argument.

data

(Optional) Name of dataset that contains x (and w) variable.

q

(Optional) The quantiles you want calculated as a number or vector of numbers. Input as percentages. For median only, q=50. For quartiles, q=c(25, 50, 75).

digits

(Optional) Number of decimal places reported in result (defaults to 3).

...

(Optional) Additional arguments passed to Hmisc::wtd.quantile function.

Examples

Run this code
   library(RCPA3)
   
   wtd.quantile(x=nes$ft.police, q=c(25, 50, 75), w=nes$wt)
   wtd.quantile(x=nes$ft.police, q=c(25, 50, 75))

Run the code above in your browser using DataLab