Subsetting vector: how to programatically pass negative index safely?
问题 Given a vector, say v = 1:10 , one can remove elements from v using negative indexing, e.g. v[-1] , v[-length(v)] , v[-c(2,3)] , to remove the first, last and 2nd/3rd element respectively. I would like to split v by passing in a split index n , taking values 0 to length(v) . The code below: v1 <- v[1:n] v2 <- v[-c(1:n)] works perfectly fine except for n = 0 . Now I know that 1:n is generally unsafe and should be replaced with seq_len(n) , however, the assignment v2 <- v[-seq_len(0)] produces