[R] how to set missing values in R

Douglas Bates bates at stat.wisc.edu
Mon Oct 27 22:19:39 CET 2003


See the recent discussion about is.na() on this list.  You can do what
you want as

> x<-c(1,3,-1,0,4)
> is.na(x) = x > 0
> x
[1] NA NA -1  0 NA

Yulei He <yuleih at umich.edu> writes:

> Hi, there.
> 
> Can I ask how to set up missing values in R? Suppose I want to assign the
> missing value to the elements in vector which is greater than zero like
> this:
> 
> x<-c(1,3,-1,0,4);
> 
> after the missing value assignment, x becomes (NA,NA,-1,0,NA).




More information about the R-help mailing list