R/seedling_death.R

Defines functions random_death

Documented in random_death

#' @title random_death
#'
#' create a function that randomly selct the seedling who has to die
#'
#' @description kills plt for the seedling info data frame
#' @param df dataframe
#' @param num_deaths ???? not sure now
#'
#' @return function ????
#' @export
random_death <- function(df, num_deaths) {

  deaths <- df %>%
    dplyr::filter(alive == 1) %>%
    dplyr::slice(sample(nrow(.), num_deaths)) %>%
    purrr::pluck("plt")
  df_tmp <- df[df$plt %in% deaths,] %>%
    dplyr::mutate(alive = 0)
  df <- dplyr::bind_rows(df %>% dplyr::filter(!plt %in% deaths),
                  df_tmp) %>%
    dplyr::arrange(site, year, plt)

  return(df)

}
mariapie/alpineplant documentation built on Dec. 21, 2021, 1:52 p.m.