Circular shift of vector (equivalent to numpy.roll)

后端 未结 4 1331
悲&欢浪女
悲&欢浪女 2020-11-28 15:25

I have a vector:

a <- c(1,2,3,4,5)

And I\'d like to do something like:

b <- roll(a, 2) # 4,5,1,2,3

Is t

4条回答
  •  离开以前
    2020-11-28 15:26

    The package binhf has the function shift:

    library(binhf)
    
    shift(1:5, places = 2)
    #[1] 4 5 1 2 3
    

    places can be positive or negative

提交回复
热议问题