left.max: Find first local maximum.

Description Usage Arguments Value See Also Examples

Description

Seeks first local maximum starting from the right hand side of given vector and moving towards left hand side.

Usage

1

Arguments

v

numeric vector

Value

numeric value of first local maximum in v starting from the end of v and going left; NA if v is nonincresing starting at last element of v and going left (i.e. v is either constant or there is minmum first)

See Also

local.min, local.max for finding local minma and maxima in vector v

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# maximum in 7 (index 2) starting from 1 (index 8) and moving with decreasing indices
v1 <- c(5,6,7,6,4,3,2,1)
# no maximum or minimum
v2 <- c(2,2,2,2,2,2)
# minimum at 2 (index 3) and no maximum starting at 6 (index 7)
v3 <- c(4,3,2,3,4,5,6)
# starting from rightmost element (3 with index 14) and going left, minimum first (in -3, index 9) then maximum (in 6, index 4)
v4 <- c(3,4,5,6,4,3,2,-1,-3,-2,0,1,2,3)
print(left.max(v1))
print(left.max(v2))
print(left.max(v3))
print(left.max(v4))

rz6/DIADEM documentation built on Dec. 31, 2019, 3:51 a.m.