Re: [R] replacing zeros with above/below numbers ?

2014-02-05 Thread Pascal Oettli
Hello, If you mean replacing 0 by the average of non-zero values, I guess one way is: a[a==0] - mean(a[a!=0]) Maybe some senior user might correct it. Regards, Pascal On 6 February 2014 12:05, ce zadi...@excite.com wrote: Dear all, My data is : a -

Re: [R] replacing zeros with above/below numbers ?

2014-02-05 Thread Jeff Newmiller
You seem to be treating zeroes as unknown values. Perhaps you should consider setting them to NA and using the na.approx function from the zoo package. --- Jeff NewmillerThe . . Go

Re: [R] replacing zeros with above/below numbers ?

2014-02-05 Thread ce
proposed na.approx function , I didn't know it, looks promising , I will look into it . ce -Original Message- From: Pascal Oettli [kri...@ymail.com] Date: 02/05/2014 10:20 PM To: ce zadi...@excite.com CC: r-help r-help@r-project.org Subject: Re: [R] replacing zeros with above/below numbers

Re: [R] replacing zeros with above/below numbers ?

2014-02-05 Thread ce
Yes , indeed this is what I am looking for : a[ a == 0.0 ] = NA na.approx(a,na.rm=FALSE) Thanks a lot. -Original Message- From: Jeff Newmiller [jdnew...@dcn.davis.ca.us] Date: 02/05/2014 10:35 PM To: ce zadi...@excite.com, r-help@r-project.org Subject: Re: [R] replacing zeros

Re: [R] replacing zeros with above/below numbers ?

2014-02-05 Thread arun
HI, May be this helps: a1 -a indx - which(c(0,diff(a!=0)) 0) indx1 - which(c(0,diff(a!=0)) 0) a[a==0] - rep( rowMeans(cbind(a[indx-1],a[indx1])),indx1-indx)  a # [1] 0.97210 0.97220 0.97300 0.97230 0.97145 0.97145 0.97145 0.97060 0.96980 #[10] 0.97040 0.97100 0.96990 #Another option is