Learn R Programming

psrwe (version 3.2)

rwe_cut: Create strata

Description

Cut a sequence of numbers into bins.

The cut points are chosen such that there will be equal numbers in each bin for x. By default, values of y that are outside the range of x will be excluded from the bins, unless they are in the keep_inx.

Usage

rwe_cut(
  x,
  y = x,
  breaks = 5,
  keep_inx = NULL,
  trim_ab = c("both", "above", "below", "none")
)

Value

A vector of stratum assignment for y. The y's that are outside the range of x and not in keep_inx are assigned NA

in the result.

Arguments

x

Vector of values based on which cut points will be determined

y

Vector of values to be cut, default to be the same as x

breaks

Number of cut points

keep_inx

Indices of y that will be categorized as 1 or the largest bin even if their values are out of range of x, i.e. the y's that will not be trimmed

trim_ab

Trim external subjects who are above or below the range of current study. Default both trims both above and below. Other options include above for above only, below for below only, and none for no trimming.

Examples

Run this code

x <- rnorm(100,  mean = 0, sd = 1)
y <- rnorm(1000, mean = 1, sd = 2)
rwe_cut(x, y, breaks = 5)

Run the code above in your browser using DataLab