'R - Share of rows in matrix with negative value in dataframe

I have a matrix that list country partners and a dataframe that lists a change (%) for each country. For each country, I would like to know the share of their partners with a negative % in ccdata. The specific values in matrix doesn't really matter, only to define the partners.

My expected output is a country list with their share of partners with negative change.

Reproducible example:

ccdata <- structure(list(Maize = c("Antigua and Barbuda", "Algeria", "Azerbaijan", 
"Albania", "Armenia", "Angola", "American Samoa", "Argentina", 
"Australia", "Bahrain", "Barbados", "Bermuda", "Bahamas", "Bangladesh", 
"Belize", "Bosnia and Herzegovina", "Bolivia", "Burma", "Benin", 
"Solomon Islands"), EPIC_RCP8.5_Long = c("-0,250", "-0,034", 
"-0,056", "-0,359", "-0,266", "-0,166", NA, "-0,068", "-0,204", 
"-0,005", "-0,330", NA, NA, "-0,373", "-0,501", "-0,274", "-0,282", 
"-0,102", "-0,460", NA)), row.names = c(NA, 20L), class = "data.frame")

matrix <- dput(maize[1:20,1:20])
structure(list(Armenia = c("0", "0", "0", "0", "0", "0", "247,9887", 
"0", "0", "0", "0", "0", "0", "0", "0", "37,8508", "0", "0", 
"0", "0"), Afghanistan = c("0", "0", "0", "0", "0", "0", "30,7517", 
"0", "0", "0", "0", "0", "0", "0", "0", "12675,368", "0", "0", 
"0", "0"), Albania = c("0", "0", "0", "0", "0", "0", "481,562", 
"0", "0", "0", "0", "0", "0", "0", "0", "116,838", "0", "0", 
"0", "33,887"), Algeria = c("0", "0", "0", "0", "0", "0", "3393028,998", 
"0", "0", "0", "0", "0", "0", "29,7409", "0", "644608,5383", 
"0", "0", "0", "0"), Angola = c("0", "0", "0", "0", "0", "0", 
"16418,9959", "0", "0", "0", "0", "0", "0", "0", "0", "738,4586", 
"0", "0", "0", "0"), Antigua.and.Barbuda = c("0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0"), Argentina = c("0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "170,5144", "0", "8369,459", "0", 
"0", "0", "0"), Australia = c("0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"
), Austria = c("0", "0", "0", "0", "0", "0", "163,0193", "0", 
"0", "0", "0", "0", "0", "0", "0", "282,1594", "0", "0", "0", 
"1931,2887"), Bahrain = c("0", "0", "0", "0", "0", "0", "24300,9685", 
"0", "0", "0", "0", "0", "0", "0", "0", "37,8551", "0", "0", 
"0", "0"), Barbados = c("0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"), 
    Bangladesh = c("0", "0", "0", "0", "0", "0", "193415,3633", 
    "0", "0", "0", "0", "0", "0", "0", "0", "1145110,277", "0", 
    "0", "0", "0"), Bhutan = c("0", "0", "0", "0", "0", "0", 
    "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
    "0", "0"), Bolivia..Plurinational.State.of. = c("0", "0", 
    "0", "0", "0", "0", "26322,8936", "0", "0", "0", "0", "0", 
    "0", "0", "0", "2672,7998", "0", "0", "0", "0"), Botswana = c("0", 
    "0", "0", "0", "0", "0", "31,1793", "0", "0", "0", "0", "0", 
    "0", "0", "0", "0", "0", "0", "0", "0"), Brazil = c("0", 
    "0", "0", "0", "0", "0", "134180,0372", "0", "0", "0", "0", 
    "0", "0", "118,1026", "0", "0", "0", "0", "0", "0"), Aruba = c("0", 
    "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
    "0", "0", "0", "0", "0", "0", "0"), Belize = c("0", "0", 
    "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
    "0", "0", "0", "0", "0", "0"), Brunei.Darussalam = c("0", 
    "0", "0", "0", "0", "0", "1397,4917", "0", "0", "0", "0", 
    "0", "0", "0", "0", "765,4375", "0", "0", "0", "0"), Bulgaria = c("0", 
    "0", "0", "0", "0", "0", "215,63", "0", "82,362", "0", "0", 
    "0", "0", "0", "0", "88,6874", "0", "0", "0", "0")), row.names = c("Armenia", 
"Afghanistan", "Albania", "Algeria", "Angola", "Antigua and Barbuda", 
"Argentina", "Australia", "Austria", "Bahrain", "Barbados", "Bangladesh", 
"Bhutan", "Bolivia (Plurinational State of)", "Botswana", "Brazil", 
"Aruba", "Belize", "Brunei Darussalam", "Bulgaria"), class = "data.frame")


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source