Get a seq() in R with alternating steps

前端 未结 6 1280
礼貌的吻别
礼貌的吻别 2020-12-17 21:19

The seq function in R would give me a sequence from x to y with a constant step m:

seq(x, y, m)
         


        
6条回答
  •  情话喂你
    2020-12-17 21:48

    First n terms of this sequence you can generate with

    x = 1; m1 = 2; m2 = 4
    
    n <- 0:10 # first 11 terms
    x + ceiling(n/2)*m1 + ceiling((n-1)/2)*m2
    # [1] 1  3  7  9 13 15 19 21 25 27 31
    

提交回复
热议问题