remove the last element of a vector

后端 未结 4 604
猫巷女王i
猫巷女王i 2020-12-14 14:29

I need to remove the last number in a groups of vectors, i.e.:

v <- 1:3
v1 <- 4:8

should become:

v <- 1:2
v1 <-         


        
4条回答
  •  一个人的身影
    2020-12-14 14:51

    Use length to get the length of the object and - to remove the last one.

    v[-length(v)]
    

    A negative index in R extracts everything but the given indices.

提交回复
热议问题