I have a list - distances
in R. What is the simplest way to return the key-value pair in the list that contains the minimum value?
I understand the actual minimum value can be found with min(unlist(distances))
, but is there a one line solution to finding the corresponding key and minimum value in the list? The output should be something like [[2]] , 36.40016
distances
[[1]]
[,1]
[1,] 144.7077
[[2]]
[,1]
[1,] 36.40016
> dput(distances)
list(structure(144.707681719953, .Dim = c(1L, 1L)), structure(36.4001632486179, .Dim = c(1L,
1L)))