nalevs {weights}R Documentation

Recode variables to 0-1 scale

Description

nalevs takes as an input any vector and recodes it to range from 0 to 1, to treat specified levels as missing, to treat specified levels as 0, 1, .5, or the mean (weighted or unweighted) of the levels present after coding.

Usage

nalevs(x, naset=NULL, setmid=NULL, set1=NULL, set0=NULL,
setmean=NULL, weight=NULL)

Arguments

x

A vector to be recoded to range from 0 to 1.

naset

A vector of values of x to be coded as NA.

setmid

A vector of values of x to be recoded to .5.

set1

A vector of values of x to be recoded to 1.

set0

A vector of values of x to be recoded to 0.

setmean

A vector of values of x to be recoded to the mean (if no weight is specified) or weighted mean (if a weight is specified) of values of x after all recoding.

weight

A vector of weights for x if weighted means are desired for values listed for setmean.

Value

A vector of length equal to that of x of class numeric.

Author(s)

Josh Pasek, Assistant Professor of Communication Studies at the University of Michigan (www.joshpasek.com).

Examples

data(anes04)
summary(anes04$age)
summary(nalevs(anes04$age))
table(anes04$educcats)
table(nalevs(anes04$educcats, naset=c(2, 4)))

[Package weights version 1.0.4 Index]