gpt4 book ai didi

r - 按 r 中的 rowname 求和不符合矩阵

转载 作者:行者123 更新时间:2023-12-04 01:12:21 24 4
gpt4 key购买 nike

我有两个大小不等的矩阵,这是一个小样本(我的真实矩阵要大得多):

s <- matrix(1:36, nrow = 6, ncol = 6, byrow=TRUE, dimnames = list(c("Afghanistan","Albania","Algeria","Argentina","Australia","Austria"), c("Afghanistan","Albania","Algeria","Argentina","Australia","Austria")))
s2 <- matrix(1:18, nrow = 3, ncol = 3, byrow=TRUE, dimnames = list(c("Albania","Algeria","Australia"), c("Albania","Algeria","Australia")))
我想按行名对国家/地区值求和。由于两个矩阵中只存在一些行名,我需要将行名相互匹配,然后对匹配的值求和。我怎样才能做到这一点?
这是我想要的输出,将“s2”中的值添加到第一个矩阵“s”中:
enter image description here
以下是我的完整数据的 dput:
> dput(head(s))
structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 93, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9937, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 281786, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1.33333333333333, 0, 0, 0, 0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, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 33000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 498766.333333333, 0, 0, 0,
0, 0, 103470.333333333, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0), .Dim = c(6L, 179L), .Dimnames = list(c("Afghanistan",
"Albania", "Algeria", "Antigua and Barbuda", "Argentina", "Armenia"
), c("Afghanistan", "Albania", "Algeria", "Antigua and Barbuda",
"Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
"Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",
"Belize", "Bermuda", "Bhutan", "Bolivia (Plurinational State of)",
"Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei Darussalam",
"Bulgaria", "Burkina Faso", "Burundi", "Côte d'Ivoire", "Cabo Verde",
"Cambodia", "Cameroon", "Canada", "Central African Republic",
"Chile", "China, Hong Kong SAR", "China, Macao SAR", "China, mainland",
"China, Taiwan Province of", "Colombia", "Comoros", "Congo",
"Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica",
"Ecuador", "Egypt", "El Salvador", "Estonia", "Eswatini", "Ethiopia",
"Faroe Islands", "Fiji", "Finland", "France", "French Polynesia",
"Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Greenland",
"Guatemala", "Guinea", "Guyana", "Honduras", "Hungary", "Iceland",
"India", "Indonesia", "Iran (Islamic Republic of)", "Ireland",
"Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan",
"Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Latvia", "Lebanon",
"Libya", "Lithuania", "Luxembourg", "Madagascar", "Malawi", "Malaysia",
"Maldives", "Mali", "Malta", "Mauritania", "Mauritius", "Mexico",
"Mongolia", "Montenegro", "Morocco", "Namibia", "Nepal", "Netherlands",
"New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria",
"North Macedonia", "Norway", "Oman", "Pakistan", "Panama", "Papua New Guinea",
"Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Qatar",
"Republic of Korea", "Republic of Moldova", "Romania", "Russian Federation",
"Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines",
"Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia",
"Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia",
"Solomon Islands", "South Africa", "Spain", "Sri Lanka", "Suriname",
"Sweden", "Switzerland", "Thailand", "Togo", "Tonga", "Tunisia",
"Turkey", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom of Great Britain and Northern Ireland",
"United Republic of Tanzania", "United States of America", "Uruguay",
"Vanuatu", "Venezuela (Bolivarian Republic of)", "Yemen", "Zambia",
"Zimbabwe", "Unspecified Area", "Viet Nam", "Syrian Arab Republic",
"Myanmar", "Benin", "Mozambique", "Trinidad and Tobago", "Lao People's Democratic Republic",
"Tajikistan", "Angola", "Iraq", "D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, 67.92,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 9.72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(6L, 181L), .Dimnames = list(
c("Albania", "Algeria", "Antigua and Barbuda", "Argentina",
"Armenia", "Aruba"), c("Albania", "Algeria", "Antigua and Barbuda",
"Argentina", "Armenia", "Aruba", "Australia", "Austria",
"Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados",
"Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan",
"Bolivia (Plurinational State of)", "Bosnia and Herzegovina",
"Botswana", "Brazil", "Brunei Darussalam", "Bulgaria", "Burkina Faso",
"Burundi", "Côte d'Ivoire", "Cabo Verde", "Cambodia", "Cameroon",
"Canada", "Central African Republic", "Chile", "China, Hong Kong SAR",
"China, Macao SAR", "China, mainland", "China, Taiwan Province of",
"Colombia", "Comoros", "Congo", "Cook Islands", "Costa Rica",
"Croatia", "Cuba", "Cyprus", "Czechia", "Democratic Republic of the Congo",
"Denmark", "Djibouti", "Dominica", "Ecuador", "Egypt", "El Salvador",
"Estonia", "Eswatini", "Ethiopia", "Faroe Islands", "Fiji",
"Finland", "France", "French Polynesia", "Gabon", "Gambia",
"Georgia", "Germany", "Ghana", "Greece", "Greenland", "Grenada",
"Guatemala", "Guinea", "Guyana", "Honduras", "Hungary", "Iceland",
"India", "Indonesia", "Iran (Islamic Republic of)", "Ireland",
"Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan",
"Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Latvia", "Lebanon",
"Libya", "Lithuania", "Luxembourg", "Madagascar", "Malawi",
"Malaysia", "Maldives", "Mali", "Malta", "Mauritania", "Mauritius",
"Mexico", "Mongolia", "Montenegro", "Montserrat", "Morocco",
"Namibia", "Nepal", "Netherlands", "New Caledonia", "New Zealand",
"Nicaragua", "Niger", "Nigeria", "North Macedonia", "Norway",
"Oman", "Pakistan", "Panama", "Papua New Guinea", "Paraguay",
"Peru", "Philippines", "Poland", "Portugal", "Qatar", "Republic of Korea",
"Republic of Moldova", "Romania", "Russian Federation", "Rwanda",
"Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines",
"Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia",
"Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia",
"Solomon Islands", "South Africa", "Spain", "Sri Lanka",
"Suriname", "Sweden", "Switzerland", "Thailand", "Togo",
"Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Tuvalu",
"Uganda", "Ukraine", "United Arab Emirates", "United Kingdom of Great Britain and Northern Ireland",
"United Republic of Tanzania", "United States of America",
"Uruguay", "Vanuatu", "Venezuela (Bolivarian Republic of)",
"Yemen", "Zambia", "Zimbabwe", "South Sudan", "Unspecified Area",
"Viet Nam", "Myanmar", "Equatorial Guinea", "Dominican Republic",
"Syrian Arab Republic", "Mozambique", "Angola", "Democratic People's Republic of Korea"
)))


例如阿富汗包含在“s”中,但不包含在“s2”中。

最佳答案

我希望我理解正确。如果没有,请提供您想要作为最终输出达到的矩阵。

s <- matrix(1:36, nrow = 6, ncol = 6, byrow=TRUE, dimnames = list(c("Afghanistan","Albania","Algeria","Argentina","Australia","Austria"), c("Afghanistan","Albania","Algeria","Argentina","Australia","Austria")))
s2 <- matrix(1:18, nrow = 3, ncol = 3, byrow=TRUE, dimnames = list(c("Albania","Algeria","Australia"), c("Albania","Algeria","Australia")))

s_new<-s[rownames(s) %in% rownames(s2),]
s_new<-s_new[, colnames(s_new) %in% colnames(s2)]

s_new<-s_new[,order(colnames(s_new))]
s2<-s2[,order(colnames(s2))]

Final<-s_new+s2

关于r - 按 r 中的 rowname 求和不符合矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64430919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com