r - 根据其他列表 R 提取列表的值

标签 r list select

给定三个列表 ABC,包含裁剪产量 及其纬度经度 分别。 列表中的每个数据框具有不同的列数,但三个列表具有相同的维度

我想应用一个函数,比如获取 A 中每行的 max:

S=lapply(A, function(x) apply(x, 1, max))

问题:如何获取BC中对应的值及其列索引,例如which.max 这样我就可以说 A 中的最大裁剪产量位于纬度 Y经度 X

然后我将制作一个包含列 A.maxLatLon

的数据框

欢迎使用其他方式来合并三个列表以方便索引。

谢谢。

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/

相关文章:

reactjs - Antd 如何固定多选组件的大小?

mySQL:SELECT 引用另一个表,没有 JOIN

同时重命名存储在列表中的数据框中的多个列

r - ipython-notebook:将 rmagic 图打印为 svg

r - 将值分配给 R 中两列值的组合

list - Elixir:生成给定参数出现 `n` 次的列表(类似于 Haskell 的复制)

python - 如何偶尔为长时间运行的 Python 列表理解提供反馈

java - JList 不显示我的组合框中新添加的元素

r - 为什么我不能在 RStudio 中安装 "forecast"包?

sql - 如何重用 2 个相同子查询检索到的值?