Skip to content

Various ways to create a sequential counter in R

Notifications You must be signed in to change notification settings

seebruck/sequential

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 

Repository files navigation

Say you want to count by eights, from a given starting point (25) to a certain threshold (1000). Here are some ways to do that in R:

Vector of Sequences

seq(25,1000,8)
seq(from = 25, to = 1000, by = 8)

For-Loop

for(i in seq(25,1000,8)) {
     print(i)
}

# or, more simply:
for(i in seq(25,1000,8)) print(i)

While-Loop

x <- 25
while(x <= 1000) { 
    print(x <- x+8) 
}

# or, more simply:
x <- 25
while(x <= 1000) print(x <- x+8)

Repeat-Loop

x <- 25
repeat {
  print(x)
  x <- x+8
  if (x >= 1000){
   break
 }
}

About

Various ways to create a sequential counter in R

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published