我在r中有一张带有标准残差的表格。如何打印具有最大值的列和行名称的向量?
negative positive
drug_1 -2.0663666 2.0663666
drug_2 1.1561265 -1.1561265
drug_3 0.6446097 -0.6446097
我想获得[1]“ drug_1”“阳性” 非常感谢您的帮助!
答案 0 :(得分:0)
您可以为任务编写自己的函数:
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"
数据:
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")
)