[R] Recode variable as NA
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Oct 30 09:06:46 CEST 2004
On Sat, 30 Oct 2004, Neil Leonard wrote:
> I was wondering how I would recode a variable as being NA (or missing).
It is the values, not the variable that are NA. For example
x <- 1:20
ind <- x%%4==0
ind
x[ind] <- NA # or is.na(x[ind]) <- TRUE
That works for logical, integer, numeric, complex and character variables.
(Raw and list vecctors do not have missing values.)
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list