R/dist_transform.R

#' Get the distance transformation between X and Y coordinates.
#'
#' @keywords dist_transform
#' \code{dist_transform} returns a vector of distance values from xy coordinates.
#' It is usable for any of the sports that the Stat Crew tracks (basketball, lacrosse, soccer). The returned vector should be assigned to a new column in the original dataframe.
#' @export
#' @param data a dataframe object
#' @param sport_type a character argument which can be "bball", "lax", or "soccer".
#' @param x_col column of x coordinates
#' @param y_col column of y coordinates




dist_transform <- function(data, sport_type, x_col, y_col){

    bball_halfcourt <- 470

    if (sport_type == "bball"){

        ifelse(data$x < bball_halfcourt,
               (sqrt(((data$x-50)^2) + ((data$y-250)^2))),
               ifelse(data$x > bball_halfcourt,
                      (sqrt(((data$x-885)^2) + ((data$y-250)^2))), NA))


    # TODO: Lax Distance Transformation
    } else if (sport_type == "lax"){

        NA # currently returns NA

    # TODO: Soccer Distance Transformation
    } else if (sport_type == "soccer"){

        NA # currently returns NA

    }
}
mistermichaelll/statcrewRC documentation built on June 1, 2019, 3:57 a.m.