s-news
[Top] [All Lists]

Re: linear interpolation through missing data

To: "Lambert.Winnie" <lambert.winnie@ensco.com>
Subject: Re: linear interpolation through missing data
From: Sundar Dorai-Raj <sundar.dorai-raj@PDF.COM>
Date: Tue, 24 Aug 2004 17:13:44 -0700
Cc: S-PLUS Newsgroup <s-news@lists.biostat.wustl.edu>
In-reply-to: <8986151694190742869D08450EE4DCDE4508D9@amu-exch.ensco.win>
Organization: PDF Solutions, Inc.
References: <8986151694190742869D08450EE4DCDE4508D9@amu-exch.ensco.win>
Reply-to: sundar.dorai-raj@PDF.COM
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)


Lambert.Winnie wrote:

S-PLUS6 on Windows XP
I found this question in 3 emails in the archive, but did not see an answer. I have looked in my S-PLUS books, but perhaps am looking in the wrong place for the wrong thing. I want to do a relatively simple linear interpolation across missing values in a vector, e.g. ...850 862 875 NA NA 927 946... weighted by another non-missing (and never missing!) variable. Is there a function for this? If not, I can trudge through and figure out an algorithm, but would rather not waste time if I can do it in a one-liner. Thanks much.

Try ?approx. You'll need to supply an `x' but here's an example to help:

set.seed(1)
n <- 100
y <- sort(rnorm(n))
x <- seq(n)
na <- sample(n, 3) # remove 3 points
guess <- approx(x[-na], y[-na], xout = x[na])$y
cbind(true = y[na], guess)

--sundar



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