Let's assume I have this vector v:
v
v = seq(1,30,1)
I write this simple loop:
for(i in v) { print(i) }
However, I would like to write a loop that gives me, in time, 1:2, 3:4, 5:6, 7:8, etc. I would then get:
[1] 1,2 [1] 3,4 [1] 5,6 [1] 7,8 ...
Can anyone help me?
Thanks!
Maybe you can generate v with step of 2.
v = seq(1,30,2) for(i in v) { cat(paste(i, i + 1, sep = ','), ' ') } #1,2 #3,4 #5,6 #7,8 #9,10 #11,12 #13,14 #...
2.1m questions
2.1m answers
60 comments
57.0k users