For loop step including last value
You can save some typing if you declare a variable for where your range ends:

for (start.i in seq(1, lengthdata, stepsize)){
  end.i &lt;- if (i + stepsize &gt; lengthdata) lengthdata else i + stepsize
  ## call function (start.i, end.i)
  print(paste(start.i, " - ", end.i))
}


Another improvement would be to compute end.i using the min function (less typing!)

end.i &lt;- min(start.i + stepsize, lengthdata)


As you become an advance user, you might like working with vectors directly:

start.i &lt;- seq(1, lengthdata-1, stepsize)
end.i   &lt;- pmin(start.i + stepsize, lengthdata)


and call your function(s) (e.g. paste) on all using the Map (or mapply)

output &lt;- Map(paste, start.i, " - ", end.i)


rather than use a for loop (even less typing). This is equivalent to doing:

output &lt;- list()
for (i in 1:length(start.i)) {
   output[[i]] &lt;- paste(start.i[i], " - ", end.i[i])
}