#' 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
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.