knitr::opts_chunk$set(echo = FALSE, warning=FALSE, message=FALSE,
  comment = "#>"
)
library(kwdemog)
library(dplyr)
data(orca)
year.end = as.numeric(substr(Sys.Date(),1,4))
refit_models = TRUE
report_start = year.end-5
# format whale names just for consistency
format_names = function(x) {
  for(i in 1:2) {
  indx = which(substr(x,2,2) == "0")
  x[indx] = paste0(substr(x[indx],1,1), substr(x[indx],3,nchar(x[indx])))
  }
  return(x)
}
data(ages2stages)
expanded = expand(orca, ages2stages=ages2stages)

expanded$animal = format_names(expanded$animal)
expanded$pod = format_names(expanded$pod)
expanded$matriline = format_names(expanded$matriline)
expanded$mom = format_names(expanded$mom)
expanded$dad = format_names(expanded$dad)

#report_dir = "projections/"

current_pop = dplyr::filter(expanded, year==year.end,
                            alive==1,
                            population=="SRKW") %>% 
  dplyr::select(animal,birth,age,pod,mom,sexF1M2)

# bring in stages
stages = read.csv("../inst/extdata/ages2stages.csv")
current_pop = dplyr::left_join(current_pop,stages)
current_pop$stage[which(is.na(current_pop$stage))] = "calf"
current_pop$stage[which(current_pop$stage=="young_female")] = "young female"
current_pop$stage[which(current_pop$stage=="young_male")] = "young male"
current_pop$stage[which(current_pop$stage=="old_female")] = "old female"
current_pop$stage[which(current_pop$stage=="old_male")] = "old male"

current_pop$sex = "Unk"
current_pop$sex[which(current_pop$sexF1M2==1)]="F"
current_pop$sex[which(current_pop$sexF1M2==2)]="M"

current_pop = dplyr::select(current_pop, -sexF1M2)

The table of all individuals is below, but we can also do a coarse summary by category,

knitr::kable(table(current_pop$stage),col.names=c("Stage","Freq"))
knitr::kable(current_pop)


nwfsc-cb/srkw-status documentation built on Jan. 16, 2025, 1 a.m.