R/dsp_to_matrix.R

Defines functions dsp_to_matrix

Documented in dsp_to_matrix

#' @title Creates global site by latitudinal-longitudinal grid cell
#' dispersion field abundance counts.
#'
#' @description Create global abundance counts matrix by merging the dispersion
#' fields from the list of dispersion field maps generated by
#' \code{dsp_create_from_survey} or \code{dsp_create_from_gdb} function.
#'
#' @param dispersion.field Dispersion field list generated by
#'                        \code{dsp_create_from_survey} or
#'                        \code{dsp_create_from_gdb} function.
#'
#' @return The global site by grid cell abundance counts matrix.
#' @keywords dispersion field, global abundance counts
#'
#' @examples
#'
#' data("dispersion_field_ex")
#' mat <- dsp_to_matrix(dispersion_field_ex)
#'
#'
#' @export

dsp_to_matrix  = function(dispersion.field)
{
  map_data <- vector()
  for(l in 1:length(dispersion.field)){
    temp_data <- dispersion.field[[l]];
    temp_data[is.na(temp_data)] <- 0;
    temp_data_vec <- matrix(as.matrix(temp_data),
                            ncol=dim(temp_data)[1]*dim(temp_data)[2], byrow=TRUE);
    map_data <- rbind(map_data, temp_data_vec);
  }
  rownames(map_data) <- names(dispersion.field)
  return(map_data)
}
kkdey/ecostructure documentation built on Jan. 26, 2021, 4:10 p.m.