If you can always rely on a period of one month, then temporarily cancel the time information:
temps <- Nino3.4_1974_2000$Nino3.4_degree_1974_2000_plain
So, since each temperature in this vector is always divided by one month, we just need to look for runs where temps[i]>=0.5 , and the run should be at least 5.
If we do the following:
ofinterest <- temps >= 0.5
we will have a vector ofinterest with values TRUE FALSE FALSE TRUE TRUE .... etc., where it is TRUE when temps[i] was> = 0.5 and FALSE otherwise.
To rephrase your problem, we just need to look for occurrences of at least five TRUE per line .
For this we can use the rle function. ?rle gives:
> ?rle Description Compute the lengths and values of runs of equal values in a vector - or the reverse operation. Value: 'rle()' returns an object of class '"rle"' which is a list with components: lengths: an integer vector containing the length of each run. values: a vector of the same length as 'lengths' with the corresponding values.
So, we use rle , which counts all the rows of a sequential TRUE in a row and sequential FALSE in a row and looks for at least 5 TRUE in a row.
I will just do some data to demonstrate:
# for you, temps <- Nino3.4_1974_2000$Nino3.4_degree_1974_2000_plain temps <- runif(1000)
Now, if you make Nino3.4_1974_2000$Month_common[startMonths] , you will get all the months that El Nino started.
It comes down to a few lines:
runs <- rle(Nino3.4_1974_2000$Nino3.4_degree_1974_2000_plain>=0.5) streakIs <- which(runs$lengths>=5 & runs$values) startMonths <- sapply(streakIs, function(n) sum(runs$lengths[1:(n-1)])+1) Nino3.4_1974_2000$Month_common[startMonths]