def build_m(df_data, dimension1, binary=True, filter_col=None, filter_val=None
    ):
    """
    Build matrix binary M by computing the RCA of every instance of dimension 1

    :param df_data: (Dataframe) each row is a instance of dimension1 in a YEAR, other columns are functions.
    :param dimension1: (string) first dimension of the problem (name of the column in df_data)
    :param year: (int) year of interest
    :param binary : (bool) True to get M matrix, False to get RCA matrix
    :return: (Dataframe) Matrix M
    """
    if filter_col:
        df_nat = df_data[df_data[filter_col] == filter_val]
        df_cp = df_nat.groupby(by=[dimension1, filter_col]).sum()
    else:
        df_nat = df_data
        df_cp = df_nat.groupby(by=[dimension1]).sum()
    df_nat = df_cp.sum(axis=1)
    df_num = df_cp.astype(float).div(df_nat, axis=0).astype(float)
    df_prod = df_cp.sum(axis=0)
    df_tot = df_prod.sum()
    df_denum = df_prod / df_tot
    if filter_col:
        df = df_num.div(df_denum).reset_index().drop(filter_col, 1).set_index(
            dimension1)
    else:
        df = df_num.div(df_denum).reset_index().set_index(dimension1)
    if binary:
        df = df.apply(lambda x: x > 1).astype(int)
    return df
