gpt4 book ai didi

r - 与语言 R 匹配以获得位置

转载 作者:行者123 更新时间:2023-12-03 15:25:58 24 4
gpt4 key购买 nike

我正在使用匹配来获取元素是否在列表中。例如我的 list 是:

  c("a","b","h","e"...) and so on

如果我想查看元素 h 是否在列表中,我正在以这种方式使用 match:
  if ("h" %in% v){do something}

我如何获得它在列表中找到元素的位置?
谢谢

最佳答案

如果您想知道职位,请使用 which

l <- c("a","b","h","e")
which(l=='h')
[1] 3 # It'll give you the position, 'h' is the third element of 'l'

请注意 l是一个向量,而不是你提到的列表。

关于r - 与语言 R 匹配以获得位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12786005/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com