[R] analog to the matlab buffer function?

Robin Hankin r.hankin at noc.soton.ac.uk
Fri Dec 1 09:16:49 CET 2006


 > do.call("rbind",lapply(0:4,function(i){i+(1:5)}))
      [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    3    4    5
[2,]    2    3    4    5    6
[3,]    3    4    5    6    7
[4,]    4    5    6    7    8
[5,]    5    6    7    8    9
 >



On 1 Dec 2006, at 00:32, Charles C. Berry wrote:

>
> See
>
>  	?embed
>
> It is not quite the same, but this seems to be what you want - at  
> least
> for the example you give:
>
>> t( embed(1:5,3) )[3:1,]
>       [,1] [,2] [,3]
> [1,]    1    2    3
> [2,]    2    3    4
> [3,]    3    4    5
>>
>
> On Fri, 1 Dec 2006, Martin Ivanov wrote:
>
>> Hello! I am new to R. I could not find a function analogous to  
>> matlab's
>> function buffer, which is used in signal processing. Is there such a
>> function in R? What I need to do is as follows. If I apply the  
>> function
>> to the vector c(1:5) for example with a window length 3 and  
>> overlapping
>> 2, I need to get a matrix like this:
>> 1 2 3
>> 2 3 4
>> 3 4 5
>> In matlab this is achieved with the function buffer. Is there  
>> ananalogous R function?
>>
>> Thank you very much in advance.
>> Regards,
>> Martin
>>
>> ______________________________________________
>> R-help at 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
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> Charles C. Berry                        (858) 534-2098
>                                           Dept of Family/Preventive  
> Medicine
> E mailto:cberry at tajo.ucsd.edu	         UC San Diego
> http://biostat.ucsd.edu/~cberry/         La Jolla, San Diego  
> 92093-0717
>
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743




More information about the R-help mailing list