R/clean.R

Defines functions eq_clean_date eq_clean_location

Documented in eq_clean_date eq_clean_location

#' Clean earthquak dates
#'
#' @param df A data.frame such as this obtainded from NOAA.
#'
#' @return A data.frame with a tidy date column.
#' @import dplyr
#' @examples
#' \dontrun{
#' file_path <- system.file("extdata", "signif.tsv", package = "MSDR")
#' signif <- read_tsv(file_path) %>%
#'   eq_clean_date %>%
#' }
#' @export
eq_clean_date <- function(df) {
  df %>%
    dplyr::mutate(date = paste(YEAR, MONTH, DAY, ''),
           date = lubridate::ymd(date))
}

#' Clean earthquak locations
#'
#' @param df A data.frame such as this obtainded from NOAA.
#'
#' @return A data.fram with a tidy location column
#' @examples
#' \dontrun{
#' file_path <- system.file("extdata", "signif.tsv", package = "MSDR")
#' signif <- read_tsv(file_path) %>%
#'   eq_clean_date %>%
#'   eq_clean_location
#' }
#' @import dplyr stringr
#' @export
eq_clean_location <- function(df) {
  df %>%
    dplyr::mutate(LOCATION = stringr::str_split(LOCATION_NAME, ': ', simplify = TRUE)[,2],
           LOCATION = stringr::str_to_title(LOCATION_NAME))
}
TRSperzel/R-Capstone-Project documentation built on Nov. 9, 2019, 12:51 p.m.