Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在r中的标准残差表中查找具有最大值的列和行名称_R - Fatal编程技术网

在r中的标准残差表中查找具有最大值的列和行名称

在r中的标准残差表中查找具有最大值的列和行名称,r,R,我有一张r表格,上面有标准残差。如何打印具有最大值的列和行名称的向量 negative positive drug_1 -2.0663666 2.0663666 drug_2 1.1561265 -1.1561265 drug_3 0.6446097 -0.6446097 我想让[1]“药物1”呈阳性 非常感谢你的帮助 您可以为任务编写自己的函数: where_max <- function(y) { where <- which(y

我有一张r表格,上面有标准残差。如何打印具有最大值的列和行名称的向量

          negative   positive
  drug_1 -2.0663666  2.0663666
  drug_2  1.1561265 -1.1561265
  drug_3  0.6446097 -0.6446097
我想让[1]“药物1”呈阳性
非常感谢你的帮助

您可以为任务编写自己的函数:

where_max <- function(y) {
  where <- which(y == max(y), arr.ind = TRUE)
  c(row.names(y)[where[1]], colnames(y)[where[2]])
}
where_max(x)
[1] "drug_1"   "positive"

其中_max正数和负数都具有相同的最大值。
x <- structure(
  list(
    negative = c(-2.0663666, 1.1561265, 0.6446097), 
    positive = c(2.0663666, -1.1561265, -0.6446097)
  ), 
  class = "data.frame", 
  row.names = c("drug_1", "drug_2", "drug_3")
)