-1

I would like to create the follow sequence without a loop for a value d greater equal 1:

c(d:2, d:3, d:4, ..., d:(d-1), d)

Is this possible?

Thank you in advance!

anjo1659
  • 41
  • 5
  • Do you mean c(1:1, 1:2, ...1:d)? Because assume d equals 4, then you'd get c(4:2, 4:3, 4:4 and so on), but you probably want (1:2, 1:3, 1:4)? So can you share teh expected outcome for a certain d value, e.g. 4 or 5? – deschen Sep 30 '21 at 11:25
  • `lapply(2:d, function(x) seq(d, x))` – Ronak Shah Sep 30 '21 at 11:30

1 Answers1

0

If you want from 1 to d

sapply(1:d,function(x){seq(x,d)})

if you want from d to 1

sapply(1:d,function(x){seq(d,x)})
user2974951
  • 9,535
  • 1
  • 17
  • 24