R/totgoals.R

#' Return all instances of a team being involved in a game with n goals
#'
#' @param df The results dataframe
#' @param N Number of goals
#' @param teamname teamname
#' @return a dataframe with  matches
#' @importFrom magrittr "%>%"
#' @examples
#' totgoals(england, 10, "York City")
#' totgoals(england, 12, "Aston Villa")
#'
#' @export

totgoals<-function (df=NULL, N=NULL, teamname=NULL) {

  totgoal<-score1<-n<-.<-key<-Date<-tier<-home<-team<-visitor<-hgoal<-vgoal<-goaldif<-FT<-Season<-division<-result<-maxgoal<-mingoal<-absgoaldif<-NULL

  df %>%
    dplyr::mutate(totgoal = hgoal+vgoal) %>%
    dplyr::filter(totgoal >= N, home == teamname | visitor == teamname) %>%
    dplyr::select(Date, Season,home,visitor,FT, totgoal, tier) %>%
    dplyr::arrange(-totgoal, Season)
}

Try the engsoccerdata package in your browser

Any scripts or data that you put into this service are public.

engsoccerdata documentation built on May 2, 2019, 8:29 a.m.