I am trying to create a regular sequence of numbers that are alternating between an increasing integer and zeros. e.g.
0,1,0,2,0,3,0,4 ... up to some value that I need functionally specify.
I am trying to create a regular sequence of numbers that are alternating between an increasing integer and zeros. e.g.
0,1,0,2,0,3,0,4 ... up to some value that I need functionally specify.
You can use this.
n = 10
as.vector(rbind(rep(0,n), (1:n)))
Result:
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10
Function f(n)
gives you the result you are after:
f <- function(n){
i <- 1:(2*n)
ifelse(i %% 2, 0, i/2)
}
f(5)
# 0 1 0 2 0 3 0 4 0 5