r - For each element of given vector, generate sequence with X, X-1, ..., X-(N-1) -


so have been trouble creating counter, able help. lets have vector

x <- c(40,10,60) 

the desired output new matrix 3 x n each row being new date looking this..

40 39 38 37 36 35 34 33 32 31 30... 10 9 8 7 6 5 4 3 2 1 0 0 0  60 59 58 57 56 55 54 53 52 51 50   

what want row subtract 1 previous entry n number of times. how go doing this?

any appreciated.

> n = 12 # or whatever want  > t(sapply(c(40,10,60), function(x) pmax(seq(x, (x-n+1), -1), 0) ))      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [1,]   40   39   38   37   36   35   34   33   32    31    30    29    28 [2,]   10    9    8    7    6    5    4    3    2     1     0     0     0 [3,]   60   59   58   57   56   55   54   53   52    51    50    49    48 

Comments