gpt4 book ai didi

r - 检查 R 中向量中的值

转载 作者:行者123 更新时间:2023-12-01 13:39:40 25 4
gpt4 key购买 nike

Refer the below code. id <- 1:10. How the warning can be avoided?

allFiles <- list.files(directory)

fileRange <- c(1:length(allFiles))
if(!(as.numeric(id) %in% fileRange))
{
print("Invalid file range")
stop()
}
Warning: the condition has length > 1 and only the first element will be used

最佳答案

要检查一个向量是否完全位于另一个向量中,请使用 all:

if ( all(x %in% y) )

关于r - 检查 R 中向量中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32681090/

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