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 best yong
how to replace NaN in a vector
3 messages · Yong Wang, Duncan Murdoch, David Scott
On Mon, 8 Mar 2004 18:18:28 -0600 (CST), you 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?
x[is.nan(x)] <- 42 See ?NaN for related functions. Duncan Murdoch
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