R:which.min似乎在我的数据框中不起作用

Kae*_*vas 1 r which

对这个新手问题我很抱歉.我有一个数据框

l_tab$dis2_num$perc
  Var1        dis       pol        dif
1    1 0.79867550 0.2198391 0.57883635
2    2 0.14569536 0.1983914 0.05269606
3    3 0.05562914 0.5817694 0.52614030
Run Code Online (Sandbox Code Playgroud)

我想在哪里找到dif的最小值.我试过这个:

> min(l_tab$dis2_num$perc["dif"])
>[1] 0.05269606
Run Code Online (Sandbox Code Playgroud)

这是正确的,但我想恢复行(在这种情况下2)

搜索这些东西,我试试这个:

在其他数据框中排序和查找值

推荐函数which.min().

当我尝试将此应用于我的数据时出现问题

> which.min(l_tab$dis2_num$perc["dif"])
Erreur dans which.min(l_tab$dis2_num$perc["dif"]) : 
  the objet (list) can't be converted to type 'double'

> typeof(l_tab$dis2_num$perc)
[1] "list"
Run Code Online (Sandbox Code Playgroud)

我不明白为什么我的数据框已成为一个列表.

我也尝试过这个

> r = as.data.frame(r)
> r

  Var1        dis       pol        dif
1    1 0.79867550 0.2198391 0.57883635
2    2 0.14569536 0.1983914 0.05269606
3    3 0.05562914 0.5817694 0.52614030

> typeof(r)
[1] "list"
Run Code Online (Sandbox Code Playgroud)

没有任何结果......

建议?

Fer*_*ndo 5

data.frame是一个列表并[返回一个子列表.相反,要提取列表项(向量),您可以执行以下操作:

 which.min(l_tab$dis2_num$perc[["dif"]])
Run Code Online (Sandbox Code Playgroud)

要么

 which.min(l_tab$dis2_num$perc$dif)
Run Code Online (Sandbox Code Playgroud)