Re: [R] values in between

From: Jim Lemon <bitwrit_at_ozemail.com.au>
Date: Fri 02 Dec 2005 - 13:34:51 EST

Eric C. Jennings wrote:
> Hey there
>
> I have two vectors:
>
> y<- c(0.4, 0.0, 0.2, -0.2, -0.6, 0.2, 0.0, 0.0, 0.4, 0.4, 0.2)
>
> In the vector y, I want to access (in the order given) all of the values in
> between each of the specific values of given.
>
> I understand subsetting with y[i], but how do I get to ssomewhere in
> between -0.6 and 0.2?
>
Hi Eric,

There was a function "filter" in the ts package, but that package seems to have disappeared. A Q&D function that would do what you want is:

wapply<-function(x,window=2,FUN=mean,mode="numeric",...) {   w1<-window-1
  l1<-length(x)-w1
  wout<-vector(mode,l1)
  for(i in 1:l1) wout[i]<-do.call(FUN,list(x=x[i:(i+w1)]))   return(wout)
}

Jim



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Dec 02 18:52:00 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:28 EST