R語言 which() 、 which.min() 、 which.max() 函數


函數 which() 可以用來找到滿足條件的下標,如

x <- c(3, 4, 3, 5, 7, 5, 9)
which(x > 5)

5 7

  

seq(along=x)[x > 5]

5 7

這里 seq(along=x) 會生成由 x 的下標組成的向量

用 which.min() 、
which.max 求最小值的下標和最大值的下標,不唯一時只取第一個。如

which.min(x)
1

which.max(x)
7

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM