I have a list of values that I want to identify local maximum and minimuma with. Theres just over 1000 numbers in total.
This is a subset of some of my numbers:
c(76.4734833333333, 76.4700041666667, 76.4705916666667, 76.4693,
76.4679, 76.4675208333333, 76.4666833333333, 76.4655291666667,
76.46565, 76.4668125, 76.4618416666667, 76.4617666666667, 76.466375,
76.4636708333333, 76.464325, 76.4638833333333, 76.4633083333333,
76.4627333333333, 76.4605541666667, 76.4601708333333, 76.4625583333333,
76.46265, 76.4607833333333, 76.4604730769231, 76.4611833333333,
76.4607291666667, 76.4613375, 76.4598166666667, 76.4579916666667,
76.4593, 76.4573291666667, 76.4560208333333, 76.4555958333333,
76.4544916666667, 76.4549875, 76.45485, 76.4542708333333, 76.4576333333333,
76.4551708333333, 76.4562208333333, 76.4550291666667, 76.4525125,
76.45145, 76.4581166666667, 76.4509125, 76.4506875, 76.4480791666667,
76.4469083333333, 76.446825, 76.4456666666667, 76.4450833333333,
76.4471166666667, 76.4454583333333, 76.4565958333333, 76.4572708333333,
76.4527166666667, 76.4499791666667, 76.4462416666667, 76.4470125,
76.4436833333333, 76.4394083333333, 76.4384083333333, 76.4380416666667,
76.4420916666667, 76.4388541666667, 76.4417416666667, 76.4382791666667,
76.4415875, 76.4379041666667, 76.4356916666667, 76.437425, 76.4351666666667,
76.4323208333333, 76.4308708333333, 76.4279583333333, 76.42345,
76.4236708333333, 76.4214541666667, 76.4135166666667, 76.4157791666667,
76.4080083333333, 76.4109583333333, 76.4063458333333, 76.4014958333333,
76.3932291666667, 76.3864208333333, 76.3806208333333, 76.3771708333333,
76.3774375, 76.4234958333333, 76.424825, 76.4310833333333, 76.4348666666667,
76.4300916666667, 76.4245625, 76.4180791666667, 76.4292083333333,
76.4327583333333, 76.4309416666667, 76.4186708333333, 76.4252375,
76.4248, 76.4411958333333, 76.4403166666667, 76.449325, 76.4444291666667,
76.4322291666667, 76.4382, 76.4252083333333, 76.4230583333333,
76.42185, 76.4090375, 76.4278958333333, 76.4500083333333, 76.4380541666667,
76.4399125)
Any ideas?
EDIT: I'd like to have a column in my dataframe of whether something is a maximum or minimum point. I.e. 1 = max, 0=neither, -1 = min.
I have seen this. But I dont know how to convert the numbers into a column. Finding local maxima and minima
My answer based on above:
(df$mAOD is the same as the list provided above). Although I'm not sure its capturing everything properly.
max <- which(diff(sign(diff(df$mAOD)))==-2)+1
df$max <- ifelse(seq_len(nrow(df)) %in% max, 1, NA)