Hi, Here is a vector and the result from the embed-command:
VECTOR=c(0,3,6,3,11,2,4,3,7,6,4,5,10,2,3,5,8) > embed(VECTOR, dimension=5) [,1] [,2] [,3] [,4] [,5] [1,] 11 3 6 3 0 [2,] 2 11 3 6 3 [3,] 4 2 11 3 6 [4,] 3 4 2 11 3 [5,] 7 3 4 2 11 [6,] 6 7 3 4 2 [7,] 4 6 7 3 4 [8,] 5 4 6 7 3 [9,] 10 5 4 6 7 [10,] 2 10 5 4 6 [11,] 3 2 10 5 4 [12,] 5 3 2 10 5 [13,] 8 5 3 2 10 Is there a way to little modify the algorithm so that the result looks like this: [1] 0 3 6 11 2 <- beginning from the first number of the VECTOR [1] 3 6 11 2 4 <- beginning from the second number of the VECTOR etc [1] 6 3 11 2 4 [1] 3 11 2 4 7 [1] 11 2 4 3 7 [1] 2 4 3 7 6 [1] 4 3 7 6 5 [1] 3 7 6 4 5 [1] 7 6 4 5 10 [1] 6 4 5 10 2 [1] 4 5 10 2 3 [1] 5 10 2 3 8 [1] 10 2 3 5 8 Every row consists of next five unique(!) member of the VECTOR. I made this example result with a time consuming algorithm which uses for-loops and whiles. How to do this better?? Thanks in advance! Atte Tenkanen University of Turku ______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.