|
9 | 9 | #' zero (i.e., if the behavior has not occurred). |
10 | 10 | #' |
11 | 11 | #' @param intensity The intensity of the behavior. |
12 | | -#' @param not_in_the_past_year Whether or not the behavior did NOT occur in |
13 | | -#' the past year. If \code{yes}, the behavior did not occur in the past year. |
| 12 | +#' @param did_not_occur Whether or not the behavior did NOT occur. If |
| 13 | +#' \code{yes}, the behavior did not occur (in the given timeframe). |
14 | 14 | #' @param frequency The frequency of the behavior. |
15 | 15 | #' @param item_names The names of the questionnaire items. |
16 | 16 | #' @param data The data object. |
17 | 17 | #' @param frequency_vars The name(s) of the variables corresponding to the |
18 | 18 | #' number of occurrences (\code{num_occurrences}). |
19 | | -#' @param not_in_past_year_vars The name(s) of the variables corresponding to |
20 | | -#' whether the behavior did not occur in the past year |
21 | | -#' (\code{not_occurred_past_year}). |
| 19 | +#' @param did_not_occur_vars The name(s) of the variables corresponding to |
| 20 | +#' whether the behavior did not occur in the past year (\code{did_not_occur}). |
22 | 21 | #' |
23 | 22 | #' @return |
24 | 23 | #' The intensity of the behavior. |
|
27 | 26 |
|
28 | 27 | #' @rdname recodeBehaviorIntensity |
29 | 28 | #' @export |
30 | | -recode_intensity <- function(intensity, not_in_the_past_year = NULL, frequency = NULL){ |
| 29 | +recode_intensity <- function(intensity, did_not_occur = NULL, frequency = NULL){ |
31 | 30 | if(missing(frequency) | is.null(frequency)){ |
32 | | - result <- ifelse(is.na(not_in_the_past_year), intensity, ifelse(not_in_the_past_year == 1, 0, intensity)) |
33 | | - } else if(missing(not_in_the_past_year) | is.null(not_in_the_past_year)){ |
| 31 | + result <- ifelse(is.na(did_not_occur), intensity, ifelse(did_not_occur == 1, 0, intensity)) |
| 32 | + } else if(missing(did_not_occur) | is.null(did_not_occur)){ |
34 | 33 | result <- ifelse(is.na(frequency), intensity, ifelse(frequency == 0, 0, intensity)) |
35 | | - } |
| 34 | + } else( |
| 35 | + result <- ifelse(did_not_occur == 1, 0, ifelse(frequency == 0, 0, intensity)) |
| 36 | + ) |
36 | 37 |
|
37 | 38 | return(result) |
38 | 39 | } |
39 | 40 |
|
40 | 41 | #' @rdname recodeBehaviorIntensity |
41 | 42 | #' @export |
42 | | -mark_intensity_as_zero <- function(item_names, data, not_in_past_year_vars = NULL, frequency_vars = NULL) { |
| 43 | +mark_intensity_as_zero <- function(item_names, data, did_not_occur_vars = NULL, frequency_vars = NULL) { |
43 | 44 | if(missing(frequency_vars) | is.null(frequency_vars)){ |
44 | 45 |
|
45 | 46 | recoded <- Map( |
46 | 47 | recode_intensity, |
47 | 48 | intensity = data[, item_names], |
48 | | - not_in_the_past_year = data[, not_in_past_year_vars]) |
| 49 | + did_not_occur = data[, did_not_occur_vars]) |
| 50 | + |
| 51 | + } else if(missing(did_not_occur_vars) | is.null(did_not_occur_vars)){ |
| 52 | + |
| 53 | + recoded <- Map( |
| 54 | + recode_intensity, |
| 55 | + intensity = data[, item_names], |
| 56 | + frequency = data[, frequency_vars]) |
49 | 57 |
|
50 | | - } else if(missing(not_in_past_year_vars) | is.null(not_in_past_year_vars)){ |
| 58 | + } else { |
51 | 59 |
|
52 | 60 | recoded <- Map( |
53 | 61 | recode_intensity, |
54 | 62 | intensity = data[, item_names], |
| 63 | + did_not_occur = data[, did_not_occur_vars], |
55 | 64 | frequency = data[, frequency_vars]) |
56 | 65 |
|
57 | 66 | } |
|
0 commit comments