给定三个列表
A
、B
和C
,包含裁剪产量
及其纬度
和经度
分别。 列表
中的每个数据框
具有不同的列数,但三个列表具有相同的维度。
我想应用一个函数,比如获取 A
中每行的 max
:
S=lapply(A, function(x) apply(x, 1, max))
问题:如何获取B
和C
中对应的值及其列索引,例如which.max
这样我就可以说 A
中的最大
裁剪产量位于纬度 Y
和经度 X
?
然后我将制作一个包含列 A.max
、Lat
、Lon
欢迎使用其他方式来合并三个列表以方便索引。
谢谢。
A =list(structure(46952.8457255653, .Dim = c(1L, 1L)), structure(c(125267.690717471,
72379.4321037455, 72468.9078338802, 13200.2611700977), .Dim = c(1L,
4L)), structure(c(26513.0496549167, 26513.0496549167, 26513.0496549167,
26513.0496549167, 26513.0496549167, 19898.5698162604, 26513.0496549167,
26513.0496549167), .Dim = c(1L, 8L)), structure(c(19814.7410087512,
39570.9565633454), .Dim = 1:2), structure(c(52291.7656702341,
52291.7656702341), .Dim = 1:2))
B =list(structure(15.3210227272727, .Dim = c(1L, 1L)), structure(c(18.5599762470309,
18.8800251256281, 18.6755033557047, 18.3664122137405), .Dim = c(1L,
4L)), structure(c(17.625, 17.625, 17.625, 17.625, 17.6262295081967,
17.5, 17.625, 17.625), .Dim = c(1L, 8L)), structure(c(18.25,
18.4964285714286), .Dim = 1:2), structure(c(19.9533582089552,
19.9633204633205), .Dim = 1:2))
C= list(structure(-84.1903409090909, .Dim = c(1L, 1L)), structure(c(-102.525534441805,
-104.263190954774, -103.906711409396, -103.88358778626), .Dim = c(1L,
4L)), structure(c(-77.6250000000001, -77.6250000000001, -77.6250000000001,
-77.6250000000001, -77.6262295081967, -77.5, -77.625, -77.625
), .Dim = c(1L, 8L)), structure(c(-69.2391304347826, -69.6303571428571
), .Dim = 1:2), structure(c(-75.8619402985075, -75.8513513513514
), .Dim = 1:2))
最佳答案
这是基本 R 的答案:
max.indices <- sapply(A, which.max)
A.max <- sapply(A, max)
Lat <- sapply(seq_along(B), function(i) B[[i]][max.indices[i]])
Lon <- sapply(seq_along(C), function(i) C[[i]][max.indices[i]])
关于r - 根据其他列表 R 提取列表的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49986503/