如果元素在列表中,我使用匹配获取.例如我的列表是:
c("a","b","h","e"...) and so on
Run Code Online (Sandbox Code Playgroud)
如果我想查看元素h是否在列表中,我将以这种方式使用匹配:
if ("h" %in% v){do something}
Run Code Online (Sandbox Code Playgroud)
我怎样才能找到它在列表中找到元素的位置?谢谢
如果你想知道位置使用 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'
Run Code Online (Sandbox Code Playgroud)
请注意,这l是一个向量,而不是您提到的列表.
| 归档时间: |
|
| 查看次数: |
1283 次 |
| 最近记录: |