Skip to content
Prev 199034 / 398525 Next

Re place only first NA in column

Hi,
On Nov 3, 2009, at 3:58 PM, bikemike42 wrote:

            
It's not really clear to me what you want to actually replace each NA  
value with. But it sounds like your 'general' question is how to find  
the index of the first value of a vector that is NA.

Let's say your `a` vector has NA values you want to replace, one by one.

any.na <- any(is.na(a))
while (any.na) {
   first.na <- which(is.na(a))[1]
   a[first.na] <- your.NA.replacing.function()
   any.na <- any(is.na(a))
}

HTH,
-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact