Skip to content
Justice Tech School

seq_along and Loop Helpers

seq_along and seq_len make safe loop indexes.

Example
x <- c("a", "b", "c")
for (i in seq_along(x)) cat(i, x[i], "\n")
print(seq_len(0))
print(rev(x))
print(which(c(F, T, T)))

Exercise

Safe indexes.

for (i in (x))

Quiz Test

Why not 1:length(x)?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.