- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个大小不等的矩阵,这是一个小样本(我的真实矩阵要大得多):
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")))
我想按行名对国家/地区值求和。由于两个矩阵中只存在一些行名,我需要将行名相互匹配,然后对匹配的值求和。我怎样才能做到这一点?
> 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, 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, 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", "Dominican Republic")))
>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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, 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/
假设我有一个名为 Tables 的矩阵列表,其中包含列名但不包含行名。 Tables <- list(structure(c(0.810145949194718, 0.079255980378851
我需要输出 A_Name、B_Name 和 C_Name。来自表A,表B,表C。我有一个包含上述所有 ID 的链接表,例如: CREATE TABLE `tableLink` ( `tableL
我有两个行数不同的数据框,因此: df1: Data1 2019-03-01 0.011 2019-04-01 0.021 2019-05-01 0.013 2019-06-01
这个问题在这里已经有了答案: Pandas Dataframe, change values on "diagonal" (where index-value is equal to column-
我有一个矩阵 A,我想将其转换为以下形式的 data.frame: rownames colnames values 使用 unlist(A) 有帮助但没有给我行名 感谢您的帮
我有两个大小不等的矩阵,这是一个小样本(我的真实矩阵要大得多): s dput(head(s)) structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
我正在尝试在由组分隔的标题下方设置列标题和水平线。当我执行以下操作时,它会起作用, library(Hmisc) data(mtcars) latex(mtcars, file ='', cgroup
我使用了以下代码: library("gplots") heatmap.2(assay(vsd)[ens_union,], trace = "none", density.info = "none")
R核心库中有两个函数。 row.names获取和设置数据框的行名 rownames检索或设置类似矩阵的对象的行名。 但是 row.names 的文档指定对于数据框,“rownames”和“colnam
像往常一样提前致谢。我已经搜索并搜索了这个问题的答案,但一无所获。 我知道变量 $userId 很好,因为回显时它会吐出数字 8。但是,当尝试在我的 Mysql 命令中使用它时,数组只是出现一个空白。
我有一个带有每日流的 csv 文件。我需要将每日值合并为每月。我正在尝试使用“hydroTSM”包的“daily2monthly”功能。 来自 BRPT2.csv 的样本数据: _date,_time
我正在将 kableExtra 库与 R Markdown 结合使用,我想向行标签(以及其他单元格的辅助标签)添加脚注。我怎样才能做到这一点 ? 下面的数据示例: library(kableExtra
我正在设计一个 Shiny 应用程序来根据各种指标对人们进行排名。使用 DT 排序功能,我希望用户能够单击任何列并按它排序。 使用行名作为排名似乎很自然;问题是这些数字与表格的其余部分一起排序。有什么
我想在 R 中通过 colnames 和 rownames 连接矩阵: m1 = matrix(c(1,2,3, 11,12,13), nrow = 2, ncol = 3, byrow = TRUE
我有以下功能供个人使用。它需要一个作者的名字来查看我的机器上是否有他们的任何软件包。 authoredPackages str(rownames(installed.packages())) Na
我需要在函数内部生成一个图,依赖于 aes_string() ,我需要标签作为行名。 下面的情节工作正常,但 不在函数内 . library(ggplot2) data(mtcars) plotfun
我有以下功能: func = t)]) }) }) } 我还有以下要传递给 func 的内容。 > scores [1] 0.187 0.975 0.566 0.793 0.524 0.481 0.0
鉴于此数据: data data[1, 1:2] age married 1 22 0 是否有某种方法可以删除任何名称并使其无名(无标签),而无需事先明确将任何内容设置为 NULL
鉴于此数据: data data[1, 1:2] age married 1 22 0 是否有一些方法可以删除任何名称并使其无名称(无标签),而无需事先将任何内容显式设置为 NUL
我很沮丧,因为我不知道如何在 data.frames 列表中实现列和行的命名。我的意思是我想避免使用循环。所以我想我可以只使用 lapply。 好的,首先我有以下列表: >a $nem.gre
我是一名优秀的程序员,十分优秀!