Calculating the maximum of sub-vectors of a larger vector

前端 未结 2 1093
攒了一身酷
攒了一身酷 2020-12-21 17:39

I would like to find the largest element in a portion of a longer vector. I would also like to perform this calculation for multiple \'pieces\' of this larger vector. The f

2条回答
  •  抹茶落季
    2020-12-21 17:50

    This should do the job

    cummax(test.vec)
    

    Besides sum, min, max, prod, for which a more efficient routine is built-in, the general strategy might be

    Reduce(max, test.vec, accumulate = TRUE)
    

提交回复
热议问题