replace.value {anchors} | R Documentation |
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.
replace.value( data, names, from=NA, to=as.integer(0), verbose = FALSE)
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) |
Will replace storage mode of 'to' with mode of 'from' in dataset.
A data frame, with the same number of observations as the input
data
, but with replaced values as specified.
Related materials and worked examples are available at http://wand.stanford.edu/anchors/
Jonathan Wand http://wand.stanford.edu
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
## 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))