Closed ben-williams closed 4 years ago
https://github.com/commfish/seak_sablefish/blob/f7bd2e40eb60552dd6131da15e529b35a6e8644c/r/llsurvey_cpue.R#L60
You could drop all of these ifelsestatements with replace_na() also case_when can help with some of the ifelse statements
ifelse
replace_na()
case_when
srv_cpue %>% filter(year >= 1997, skate_condition_cde != "02") %>% replace_na(list(bare=0, bait=0, invalid=0, sablefish=0, halibut=0, idiot=0, shortraker=0, rougheye=0, skate_general=0, longnose_skate=0, big_skate=0, sleeper_shark=0 mutate(Year = factor(year), Stat = factor(Stat), Adfg = factor(Adfg), no_hooks = no_hooks - invalid, # remove invalid hooks skates = skate_general + longnose_skate + big_skate, std_hooks = case_when(year <= 1996 ~ 2.2 * no_hooks * (1 - exp(-0.57 * (118 * 0.0254))), year == 1997 ~ 2.2 * no_hooks * (1 - exp(-0.57 * (72 * 0.0254))), year %in% c(1998, 1999), ~ 2.2 * no_hooks * (1 - exp(-0.57 * (64 * 0.0254))), TRUE ~ 2.2 * no_hooks * (1 - exp(-0.57 * (78 * 0.0254))), clotheslined = ifelse(grepl("clotheslined|Clotheslined", skate_comments) | grepl("clotheslined|Clotheslined", set_comments), 1, 0), shark = ifelse(grepl("sleeper|Sleeper|shark|sharks", skate_comments) | grepl("sleeper|Sleepershark|sharks", set_comments), 1, ifelse(sleeper_shark > 0, 1, 0))) -> srv_cpue
https://github.com/commfish/seak_sablefish/blob/f7bd2e40eb60552dd6131da15e529b35a6e8644c/r/llsurvey_cpue.R#L60
You could drop all of these
ifelse
statements withreplace_na()
alsocase_when
can help with some of the ifelse statements