[R] Generate a list of all subsequence of length k from an array

From: Ron Shefi <ron380_at_hotmail.com>
Date: Tue, 22 Jun 2010 06:35:17 +0000

Hi,
I would like to generate a list of all subsequence of length k from an array with length n (k < n). The result should be organized in a matrix. So the matrix should look like the following whereas each row is one of a subsequence of len k.

[a[1:k],
 a[2:(k+1)]
 a[3:(k+2)]

 ...
 a[(n-k+1):n]

Is there away to do this with sapply method?

thanks,
Ron                                                



The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail.

ID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4

        [[alternative HTML version deleted]]



R-help_at_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 and provide commented, minimal, self-contained, reproducible code. Received on Tue 22 Jun 2010 - 07:51:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Jun 2010 - 15:15:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive