Learn R Programming

anchors (version 3.0-8)

replace.value: Replaces occurences of a value with another value in set of columns

Description

Replaces a single value in a set of columns with another given value. This makes it easy to change the default missing value indicator, for example.

Usage

replace.value( data, names, from=NA, to=as.integer(0), verbose = FALSE)

Arguments

data
data frame
names
a vector of character strings identifying columns to be updated
from
value to find and replace, can specify vectors
to
replacement value, must be a scalar
verbose
prints warnings if typeof(from) != typeof(to)

Value

data, but with replaced values as specified.

Details

Will replace storage mode of 'to' with mode of 'from' in dataset.

References

Wand, Jonathan; Gary King; and Olivia Lau. (2007) ``Anchors: Software for Anchoring Vignettes''. Journal of Statistical Software. Forthcoming. copy at http://wand.stanford.edu/research/anchors-jss.pdf

Wand, Jonathan and Gary King. (2007) Anchoring Vignetttes in R: A (different kind of) Vignette copy at http://wand.stanford.edu/anchors/doc/anchors.pdf

See Also

anchors

Examples

Run this code
## data with zeroes as missing values in responses
data(poleff)
## data with NA missing values in responses
data(poleffna)

## convert NA to 0:
dd  <- replace.value(poleffna,c("xsayself","xsay1","xsay2","xsay3","xsay4","xsay5"))

## convert 0 to NA:
dd2 <- replace.value(poleff,c("xsayself","xsay1","xsay2","xsay3","xsay4","xsay5"),0,as.double(NA))

Run the code above in your browser using DataLab