Create a sequence from vectors with start and end positions

后端 未结 2 939
无人共我
无人共我 2020-12-21 05:21

Given two separate vectors of equal length: f.start and f.end, I would like to construct a sequence (by 1), going from f.start[1]:f.end[1] to f.start[2]:f

2条回答
  •  天命终不由人
    2020-12-21 06:02

    You can try using mapply or Map, which iterates simultaneously on your two vectors. You need to provide the function as first argument:

    vec1 = c(1,33,50)
    vec2 = c(10,34,56)
    
    unlist(Map(':',vec1, vec2))
    # [1]  1  2  3  4  5  6  7  8  9 10 33 34 50 51 52 53 54 55 56
    

    Just replace vec1 and vec2 by f.start and f.end provided all(f.start<=f.end)

提交回复
热议问题