Skip to content

Commit

Permalink
Fix for only 0s in output; NA values are now treated as Bs (values th…
Browse files Browse the repository at this point in the history
…at do not affect event status)
  • Loading branch information
adrfantini committed Feb 24, 2019
1 parent a1abf67 commit 2b4678f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ncspellR.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,12 @@ spi_spell = function(v, yrs, eventstart = -1, eventend = 0) {
stopifnot( length(v) == length(yrs) )
# Define what the labels mean, for clarity
A = 1; B = 2; C = 3
# Categorize input values: lower than eventstart (A), higher than eventend (C) and in-between (B)
# Categorize input values:
# (A) lower than eventstart, start an event
# (B) higher than eventend, stop an event if 2 consecutives are found
# (B) in-between, event status not affected
# We treat any NA as Bs
v[is.na(v)] <- (eventstart + eventend) / 2
values = as.numeric(cut(v, c(-Inf, eventstart, eventend, Inf), labels = c(A, B, C)))
# Split values and years into separate groups, divided by a C
idx <- 1 + cumsum( values == C )
Expand Down

0 comments on commit 2b4678f

Please sign in to comment.