【问题标题】:How to find rows in a matrix with only the minimum element in the first column?如何在第一列中只有最小元素的矩阵中查找行?
【发布时间】:2022-01-05 07:09:56
【问题描述】:

我正在考虑 Nelder Mead 优化技术,我需要返回第一列中具有最小值的矩阵。

我的代码:


fun <- function(x){
  3*(sin(0.5+0.25*x[2]*x[1]))*cos(x[1])
}
out <- matrix(NA, nrow=100, ncol=3)
for (i in 1:100) {
  x <- runif(1, -7, 7)
  y <- runif(1, -7, 7)
  x0 <- c(x,y)
  res <- optim(x0,fun,method="Nelder-Mead")  
  out[i,] <- round(c(res$value,res$par) , digits = 5)
} 
out

【问题讨论】:

    标签: r min


    【解决方案1】:

    使用第一列的min 创建一个逻辑向量并将矩阵子集化

    out1 <- out[out[,1] == min(out[,1]),]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      • 2015-05-05
      • 1970-01-01
      相关资源
      最近更新 更多