Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何在列表上应用which.min_R - Fatal编程技术网

R 如何在列表上应用which.min

R 如何在列表上应用which.min,r,R,假设我们有以下列表: list_1=list(c(115222.321776569, 37864639.6868223, 880844.193064039, 158574.408179366, 283899.102436544, 416531.537818319, 498992.661910475, 312537.505136515), c(498992.661910475, 33741049.3285334, 492180.657601543, 324174.022385466, 901

假设我们有以下列表:

list_1=list(c(115222.321776569, 37864639.6868223, 880844.193064039, 
158574.408179366, 283899.102436544, 416531.537818319, 498992.661910475, 
312537.505136515), c(498992.661910475, 33741049.3285334, 492180.657601543, 
324174.022385466, 901091.893188845, 106068.170722435, 115222.321776569, 
710087.526882994))

# list_1

[[1]]
[1]   115222.3 37864639.7   880844.2   158574.4   283899.1   416531.5   498992.7   312537.5

[[2]]
[1]   498992.7 33741049.3   492180.7   324174.0   901091.9   106068.2   115222.3   710087.5
可以在矩阵等列上使用which.min来获得最小索引:

mapply(function(a, b) {which.min(c(a, b))}, a = list_1[[1]], b = list_1[[2]])

# Output :

[1] 1 2 2 1 1 2 2 1
当列表的长度大于2时,我不知道如何获得该值

例如:

list_2=list(c(4,7,3),c(5,2,1),c(6,1,7))

# list_2
[[1]]
[1] 4 7 3

[[2]]
[1] 5 2 1

[[3]]
[1] 6 1 7

Output : 
> 1 3 2
提前感谢您的帮助

您可以尝试max.col+cbind

输出


这与将列表转换为矩阵相同!多谢各位!是的,do.call将创建一个矩阵,然后您可以跨行应用您的函数,因为列号对应于该值来自的列表。因此,您可以拥有所需的任意多个列表。感谢您的帮助!
> max.col(-do.call(cbind, list_1))
[1] 1 2 2 1 1 2 2 1
> max.col(-do.call(cbind, list_2))
[1] 1 3 2
apply(do.call(cbind, list_1), 1, which.min)
[1] 1 2 2 1 1 2 2 1