[R] how to replace NaN in a vector

David Scott d.scott at auckland.ac.nz
Tue Mar 9 05:05:49 CET 2004


On Mon, 8 Mar 2004, Yong Wang wrote:

> Hi, all
> 
> a vector such as
> 
> (1,2,4,-1,NaN,2,4,NaN)
> 
> if try to replace all the NaN with a numerical value, what's the easiest 
> way?
> thanks a lot
> 
> 

Is this what you wanted?

> x<-c(1,2,4,-1,NaN,2,4,NaN)
> y<-ifelse(is.nan(x),-999,x)
> y
[1]    1    2    4   -1 -999    2    4 -999



David Scott


_________________________________________________________________
David Scott	Department of Statistics, Tamaki Campus
		The University of Auckland, PB 92019
		Auckland	NEW ZEALAND
Phone: +64 9 373 7599 ext 86830		Fax: +64 9 373 7000
Email:	d.scott at auckland.ac.nz 


Graduate Officer, Department of Statistics




More information about the R-help mailing list