s-news
[Top] [All Lists]

Re: Replacing NA with a particular value

To: "Khan, Sohail" <khan@cshl.edu>, <s-news@lists.biostat.wustl.edu>
Subject: Re: Replacing NA with a particular value
From: "Petr Pikal" <petr.pikal@precheza.cz>
Date: Thu, 23 Feb 2006 09:11:20 +0100
In-reply-to: <C8696843AE995F4EA4CDC3E2B83482A901878F81@mailbox02.cshl.edu>
Hi

maybe you can use approx

> pok
  chr chr.pos abs.pos ratio
1   1    2500    3600  0.25
2   1    5600    7500    NA
3   2    1450    5200    NA
4   2    5000    7005    NA
5   2    6480    8754  0.25
6   2    5425    6542    NA
7   2    6000    8963    NA
8   2    6542    9512  0.32


apr<-approx(pok$ratio, n=length(pok$ratio))$y
vyber<-which(c(diff(apr)==0,FALSE))
pok$ratio[vyber]<-apr[vyber]

Which works with this data but I am not sure if it works with 
arbitrary values in ratio.

HTH
Petr



On 22 Feb 2006 at 23:14, Khan, Sohail wrote:

Subject:                [S] Replacing NA with a particular value
Date sent:              Wed, 22 Feb 2006 23:14:31 -0500
From:                   "Khan, Sohail" <khan@cshl.edu>
To:                     <s-news@lists.biostat.wustl.edu>

> Dear list,
> 
> I have a data frame as:
> 
> chr   chr.pos         abs.pos         ratio
> 1     2500            3600            0.25
> 1     5600            7500            NA
> 2     1450            5200            NA
> 2     5000            7005            NA
> 2     6480            8754            0.25
> 2     5425            6542            NA
> 2     6000            8963            NA
> 2     6542            9512            0.32
> 
> I would like to replace the NAs only if they occur in between the same
> values, in the data set above replace NA between 0.25 with 0.25, and
> leave the NA between 0.25 and 0.32.  Any help is greatly appreciated.
> 
> -Sohail
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news

Petr Pikal
petr.pikal@precheza.cz


<Prev in Thread] Current Thread [Next in Thread>