Skip to content

Commit 6b82a5f

Browse files
20240102 - fix function that allowed negative frequencies (now convert to NA)
1 parent c02e69a commit 6b82a5f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

R/frequencyPerDuration.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ timesPerInterval <- function(num_occurrences = NULL, interval = NULL, duration =
100100
)
101101

102102
interval_occurrences <- ifelse(
103-
(is.na(num_occurrences) | is.na(interval)) & (not_occurred_past_year == 0 | is.na(not_occurred_past_year)), NA,
103+
((is.na(num_occurrences) | is.na(interval)) & (not_occurred_past_year == 0 | is.na(not_occurred_past_year))) | num_occurrences < 0, NA,
104104
ifelse(
105105
is.na(not_occurred_past_year), num_occurrences * (duration_days / interval_days),
106106
ifelse(
@@ -123,7 +123,7 @@ timesPerLifetime <- function(num_occurrences = NULL, never_occurred = NULL) {
123123
}
124124

125125
lifetime_occurrences <- ifelse(
126-
is.na(num_occurrences) & never_occurred == 0, NA,
126+
(is.na(num_occurrences) & never_occurred == 0) | num_occurrences < 0, NA,
127127
ifelse(
128128
is.na(never_occurred), num_occurrences,
129129
ifelse(never_occurred == 1, 0, num_occurrences)))

0 commit comments

Comments
 (0)