這看起來應該很簡單,但我無法弄清楚或在網上找到解決方案。
我有一個清單
test<-list(a = list(c(4543, 25234, 56346, 676), c(545, 34647, 567567,
4564), c(785, 343, 95, 435)), b = list(c(90823, 2341, 989, 5645
), c(210938, 342345, 345, 78678), c(2094234, 2343, 23466, 45654
)))
如何找到串列中最大值的位置?
答案是test[["b"]][[3]][1]或test[[2]][[3]][1]
uj5u.com熱心網友回復:
這有點亂,但它會給你最大價值的位置
library(stringr)
library(dplyr)
x <- which.max(unlist(test))
y <- str_split(names(x), "", simplify = T)
a <- y[1]
z <- sapply(test[[a]], length) %>% cumsum
b <- which(z > as.numeric(y[2]))
c <- as.numeric(y[2]) - z[b-1]
test[[a]][[b]][[c]]
[1] 2094234
在此代碼中a,b、 和c表示位置。如果您需要更通用的版本,請告訴我
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/348920.html
上一篇:在sharedPreferences中洗掉串列中的一個元素:Flutter
下一篇:從字串中查找元音子串
