Calculating the maximum of sub-vectors of a larger vector

前端 未结 2 1068
攒了一身酷
攒了一身酷 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)
    
    0 讨论(0)
  • 2020-12-21 18:05

    You might be interested in the cummax function.

    0 讨论(0)
提交回复
热议问题