Reputation: 443
I have a return list:
test<-list(Test A
=5421.815, Test B
=5032.269, Test n
=6602.334 )
Name | Type | Value |
---|---|---|
Test | double 1 | List of lenght 7 |
Test A | double 1 | 5421.815 |
Test B | double 1 | 5032.269 |
Test n | double 1 | 6602.334 |
The min(unlist(test)) or Reduce(min,test) commands only return the desired value but not the name of the corresponding test.
5032.269
Expected return:
Test B 5032.269
Upvotes: 1
Views: 630
Reputation: 388907
test[Reduce(min, test) == test]
#$`Test B`
#[1] 5032.269
Or
test[min(unlist(test)) == test]
#$`Test B`
#[1] 5032.269
Upvotes: 1
Reputation: 887048
Use which.min
to get the index of min
imum value and then subset the list
with that index
test[which.min(test)]
#$`Test B`
#[1] 5032.269
Upvotes: 1