Does this do what you want:
> x
[1] 1 2 4 0 7 5 0 0 0 9 11 12> # create a matrix with the first column being a sequence number
> x.mat <- cbind(seq(length(x)), x)
> # remove zeros in second column
> x.mat <- x.mat[x.mat[,2] != 0,]
> x.mat
x
[1,] 1 1
[2,] 2 2
[3,] 3 4
[4,] 5 7
[5,] 6 5
[6,] 10 9
[7,] 11 11
[8,] 12 12> # now create an approxfun to interprete missing values
> x.fun <- approxfun(x.mat[,1], x.mat[,2])
> # now fill out a new matrix with interpreted values
> x.new <- cbind(seq(length(x)), x.fun(seq(length(x))))
> x.new
[,1] [,2]
[1,] 1 1.0
[2,] 2 2.0
[3,] 3 4.0
[4,] 4 5.5
[5,] 5 7.0
[6,] 6 5.0
[7,] 7 6.0
[8,] 8 7.0
[9,] 9 8.0
[10,] 10 9.0
[11,] 11 11.0
[12,] 12 12.0>
On Thu, Dec 17, 2009 at 8:16 PM, Moohwan Kim <kmhlmj2@gmail.com> wrote:
> Dear R family
>
> I have an arbitrary column vector.
> 1
> 2
> 4
> 0
> 7
> 5
> 0
> 0
> 0
> 9
> 11
> 12
> When I attempt to take natural logarithm of the series, as you guess
> there is an error message. To overcome this problem, my idea is to
> replace a zero or zeros in a row with appropriate numbers.
> In order to implement it, I need to detect where zeros are.
> Then I am going to take the average of two adjacent neighbors. In the
> case of zeros in a row, I guess I might apply the above idea
> sequentially.
>
> Would you help me out to escape from this jungle?
> Thanks in advance.
>
> Best
> Moohwan
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
>
http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
[[alternative HTML version deleted]]