【问题标题】:Is there an R function for finding the index to an element in a vector? [closed]是否有用于查找向量中元素索引的 R 函数? [关闭]
【发布时间】:2022-12-13 21:38:04
【问题描述】:

是否有用于查找向量中元素索引的 R 函数?

要查找向量中元素的索引?

【问题讨论】:

  • 编程语言 R 中的“R”?如果是这样,您为什么用 Java 和 JavaScript 标记问题?

标签: javascript java


【解决方案1】:

在这里,我们尝试查找值为 22 的元素的索引。如您所见,我们使用了 match 函数。

x_vector <- c(25,24,23,22,21)
elem <- 22
result_index <- match(elem,x_vector)
if (is.na(result_index)) {
 "There is no match found"
} else 
{  
result_index
}

有关更多信息,请查看此类似问题:Find index of an element in a vector

【讨论】:

    猜你喜欢
    • 2021-07-17
    • 2022-11-30
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 2021-08-07
    • 2016-10-27
    相关资源
    最近更新 更多