wiltonkiss
8/15/2017 - 2:39 PM

Select only London authorities from a dataframe

Select only London authorities from a dataframe

#' Filter London Boroughs
#' 
#' Filter a dataframe containing district-level data to London boroughs only
#' @param df dataframe containing a column with local authority gss codes
#' @param col_name column name containing local authority gss code. Defaults to "gss_code"
#' 
#' @export

london_only <- function(df, col_name="gss_code"){
        
        require(dplyr)
        require(data.table)
        
        df <- setnames(df, col_name, "gss_code") %>%
                filter(substr(gss_code,1,3)=="E09") %>%
                setnames("gss_code", col_name)

        return(df)
}